ä»ã¾ã§èªåã®ç 究ç¨ã³ã¼ãã®ãã¡ãã¡ã§äºåæ¨ã使ã£ã¦ããã©ãåå©ç¨ããã¾ãã§ããªãã£ããã§ã·ã³ãã«ã§å¿ç¨ã®å¹ãã¯ã©ã¹ãä½ã£ã¦ãããã¨æã£ããå ·ä½çç¨éã¯ãæ´æ°ãä½åãã®çµããå®ç¾©ããã Hoge ããããããã®ãªã¹ãã管çãããããã¨ãã°FEMã¡ãã·ã¥ã®å ´å㯠Hogeã¨ãã¦è¾ºãé¢ãåé¢ä½ãªã©ãèãããããããå«ãé ç¹ã®çªå·ã®çµã§identifyã§ãããããã¦Hogeæ§é ä½ã«ã¯åº§æ¨ã¨ãã辺ãªãã°ãããå«ãé¢ã¸ã®ãã¤ã³ã¿ãåé¢ä½ãªãã°ï¼ã¤ã®é¢ã¸ã®ãã¤ã³ã¿ãªã©ãä¿æããããããã¦æ´æ°ã®çµãããããã°ããã«å¯¾å¿ãã Hoge ãè¿ãã¯ã©ã¹ Btree ãä½ãããã
ãã¨ãã° Delaunay åå²ã¨å¼ã°ãããé ç¹ãªã¹ããç·ã§çµãã§ç©ºéãåé¢ä½ã«åå²ãã Watson ã¢ã«ã´ãªãºã ã¯ä»¥ä¸ã®ããã«ãªãã
ã»é ç¹å ¨é¨ãå«ãåé¢ä½ãä½æ for(v=å ¨ã¦ã®é ç¹) { for(f=å ¨ã¦ã®åé¢ä½è¡¨é¢ä¸è§å½¢) f->flag=0; for(t=å ¨ã¦ã®åé¢ä½) { if (vãtã®å¤æ¥åã®å é¨ã«ãã) { for (f=tã®ï¼ã¤ã®è¡¨é¢ä¸è§å½¢) { f->flag++; } delete t; } } for(f=å ¨ã¦ã®åé¢ä½è¡¨é¢ä¸è§å½¢) { if (f->flag == 2) delete f; else if (f->flag ==1) { åé¢ä½ã®ãªã¹ã += new åé¢ä½(é ç¹ v, é¢ fã®ï¼é ç¹); é¢ã®ãªã¹ã += æ°ããé¢ï¼ã¤ã é¢(é ç¹v, é¢fã®ï¼é ç¹)*3ç¨®é¡ } }//f }//v }//end
class Btree { public: void *Find(int *key); void Delete(int *key); void Insert(int *key, void *iptr); Btree(int n_key); ~Btree(); private: int nkey; BtData *Root; BtData *FindAux(int *key, BtData ***prev); void DeleteNode(BtData *p); } int main() { Btree *bt = new Btree(4); Tetra *t; int vertexlist[4] = {1,2,3,4}; t = bt->Find(vertexlist); if (t == NULL) { t = new Tetra(vertexlist, ... ,...); bt->Insert(vertexlist, t); } ... bt->Delete(vertexlist); delete bt; }
ãã¼ããæ¶ãå ´åã®å¦çãWikipediaã®èª¬æãåèã«ãªã£ããã©ã
http://en.wikipedia.org/wiki/Binary_search_tree#Deletion
ãã®ã³ã¼ããå¼æ°ã®æ¸ãæ¹ãããåãããªãããã¨ãã° left==NULL ã®æã®å¦çãrightãNULLã ã£ããèªåãæ¶ãã¦è¦ªããèªåã¸ã®ãã¤ã³ã¿ãNULLã«ããªãã¨ãããªãããã®ããã«ã¯è¦ªããèªåã¸ã®ãã¤ã³ã¿ã®ãã¤ã³ã¿ã**nodeãå¼æ°ã«ããªãã¨ãããªããããã¯ããããæ¸ãæ¹ã«ãªã£ã¦ããã ãããã
FindAux ã® Node ***prev ã¦ã®ã¯ãµã¼ããã¦ãªãã£ãå ´åãæ°ããæ¿å
¥ãã¹ããã¼ã(Node)ãæãã¦ãã親ã®ãã¤ã³ã¿(*Node)ãæ¸ãæããããã«ãã®ãã¤ã³ã¿ã®ã¢ãã¬ã¹(**Node)ãå¿
è¦ãªã®ã§ãã®å¤æ°**Nodeãç¨æãã¦ãã®ã¢ãã¬ã¹(***Node)ã渡ãã¦ãããé ãã¾ããï¼æä¸ã¤ã§ãï¼ãªãããã£ã¨ãã¾ãæ¸ãæ¹ããã®ãã
ãã¼é¢æ°ã®æ»ãå¤ã**Node ã«ãã¦ãã¼ãèªä½ã¯ãã®æã示ããã®ãã¨è¨ç®ããã°NULLã®å ´åãå«ãã¦OKã ãªã
for(t=å
¨ã¦ã®åé¢ä½)ãã¦ã®ãã©ãå®è£
ããããã¯ã©ã¹ã®ä¸ããåºãªãã¦ãããã°å帰ã§ä¸çºã ããããã ã¨å¿ç¨ãå©ããªãããªã¹ã void**List ãã¾ã¨ãã¦åã£ã¦ãããã¨ããæãããããã©ããç¾ãããªããªã
for(t= æ¨ã®ä¸çªå·¦;t!=NULL; t=次ã®t)ã¨ãããã¨ã ãä¸çªå·¦ã¯ç°¡åã ããã次ã®tããã©ããããã
ç¾å¨ã®tã®keyã+1ã ãããããã¶ãå®å¨ããªãkeyãã¾ãæ¢ããè¦ã¤ããã°OKããªãå ´åãã©ããå¤ãã§æ¢ã¾ãããã®keyããã¼ãï½ã¨ãã¦è¿½å ããå ´åããã®æ¬¡ã®å¤ãæã¤ãã¼ããï½ã¨ããã¨ãï½ã¯n->left->RightMost();ã«ãªããã¨ãããã¨ã¯ãå¤ãã«ããã¾ã§ã«æå¾ã«leftãé¸ãã æã®è¦ªãæ±ãã次ã®ãã¼ãã ã
è¨æ£ï¼ç¾å¨ã®keyãã¾ãæ¢ãããã®ãã¼ãã§right!=NULL ãªãright->LeftMost() ã次ã®å¤ãæã¤ãã¼ããright=NULLãªãããã«æ¥ãã¾ã§ã«æå¾ã«leftãåã£ãæã®è¦ªã次ã®å¤ãæã¤ãã¼ãã
for(t= Bt->LeftMost();t!=NULL; t=Bt->FindNext(t->key))ã¨ãªããã
å¿ç¨ã¨ãã¦ãã£ããããã¤ãçè¡åã®è¨ç®ã«ä½¿ã£ã¦ã¿ãã
ãããªæãããªã
#include "bitree.h" class Kij { public: int ij[2]; double mat; Kij(int i, int j); }; Kij::Kij(int i, int j) { if (i<j) { ij[0]=i; ij[1]=j; } else { ij[1]=i; ij[0]=j; } mat=0; } Btree *bt; void AddMat(int i, int j, double m0) { int key[2]; key[0]=i; key[1]=j; Kij *kij = bt->Find(key); if (kij==NULL) kij = new Kij(i,j); kij->mat += m0; }