Linked List 3 5 typedef struct listnode int Slides: 27 Download presentation 第三章 Linked List 3 -5 動態配置節點實作鏈結串列 動態配置節點,鏈結欄位改為指標 typedef struct listnode { int data; /*資料欄位*/ struct listnode *next; /*鏈結欄位*/ }NODE; NODE *list. A; 動態配置節點 list. A = (NODE *) malloc( sizeof(NODE)) ; 在C++語言中則可用 new 運算子 list. A = new NODE ; data list. A next ◎串接兩鏈結串列 -- 線性鏈結串列 A p B void List. Concate( NODE *list. A, NODE *list. B) { NODE *p = list. A ; while ( p->next != NULL) // p一路往右直到最後一個節點 p = p->next ; p->next = list. B->next ; } // 改變其鏈結 3 -8 雙向鏈結串列 typedef struct dlist_node { struct dlist_node *left; int data; struct dlist_node *right; }Dnode; Head 線性雙向鏈結串列 環狀雙向鏈結串列 Head pa 1. 初始狀態 A 5 4 6. 1 2 5 3. 2 2 2. 9 1 6 0 pb B 9 ctail C 2. pb->exp(=5) 大於 pa->exp(=4) ,複製 *pb,pb往右一個節點 pa A 5 4 6. 1 2 pb B 9 5 3. 2 2 ctail C 9 5 2. 9 1 6 0 3. pa->exp(=4) 大於 pb->exp(=2) ,複製 *pa,pa往右一個節點 pa A 5 4 6. 1 2 2. 9 1 6 0 pb B 9 5 3. 2 2 ctail C 9 5 5 4 4. pa->exp 等於 pb->exp,新節點係數為 pa->coef 加 pb->coef, pa及pb往右一個節點 pa A 5 4 6. 1 2 2. 9 1 pb B 9 5 3. 2 2 ctail C 9 5 5 4 9. 3 2 6 0 M = 0 -1 0 0 0 2 c 0 0 c 1 1 r 0 0 r 1 1 r 2 2 0 6 0 3 0 c 2 2 c 3 3 0 2 1 1 0 -1 0 0 0 1 6 c 4 4 5 × 6 c 5 5 0 4 2 1 3 6 2 1 1 r 3 3 r 4 4 2 0 0 3 3 3 4 2 2 3 5 1 4 5 6 Typedef nodeTypedef struct nodeTypedef struct tree int info struct *leftTypedef struct in cInt sum(int a int n) int sum=0 iTypedef struct node int valueTypedef struct tree int infoStruct node *nextStruct listnodeStruct node int data struct node* nextSingle linked list adalah yang paling dari semua varianSingly vs doubly linked listIntroduction to linked listPublic int divide(int a int b)Int max(int x int y)Public void drawsquare(int x, int y, int len)Interface calculator public int add class testTypedef in structureTypedef struct nodeTypedef struct studentTypedef struct cTypedef structTypedef struct tagTypedefTypedef listTypedef struct nodeCopy struct cTypedef int element