Maplewing
December 06, 2013

# 師大資工系ACM-ICPC讀書會：肆、鏈結串列與二元樹

#### Maplewing

December 06, 2013

## Transcript

3. ### struct node{ int value; node *next; }; 單向鏈結串列 Singly Linked

List 22 12 32
4. ### 插入新節點 22 12 32 5 node node.next newnode newnode.next =

node.next; node.next = newnode;
5. ### 刪除節點 22 12 32 node node.next node.next.next node *delnode =

node.next; node.next = node.next.next; delete delnode;

list

•10050

12. ### • 陣列 • 以0為root • 往編號n之左子樹：2*(n+1) - 1 • 往編號n之右子樹：2*(n+1)

• 往父節點：floor((n-1)/2) • 鏈結串列 • struct node { int data; node *left, *right; }; 儲存方式

16. ### function Preorder(node){ if(!node.left && !node.right){ print(node.value); return; } print(node.value); Preorder(node.left);

Preorder(node.right); } Ans: F,B,A,D,C,E,G,I,H 前序
17. ### function Inorder(node){ if(!node.left && !node.right){ print(node.value); return; } Preorder(node.left); print(node.value);

Preorder(node.right); } Ans: ABCDEFGHI 中序
18. ### function Postorder(node){ if(!node.left && !node.right){ print(node.value); return; } Preorder(node.left); Preorder(node.right);

print(node.value); } Ans: ACEDBHIGF 後序