[理工] [資結] 101交大 Binary Tree

看板Grad-ProbAsk作者 (MJ23)時間12年前 (2012/02/20 01:34), 編輯推噓5(500)
留言5則, 4人參與, 最新討論串1/1
下面是交大101的資料結構與演算法的題目 Struct node { int data; struct node *left,*right; }; struct node *r; void unknown(struct node *p) { struct node *q; if(p->left!=NULL) unknown(p->left); if(p->right!=NULL) unknown(p->right); q=p->left; p->left=p->right; p->right=q; } (1) Which order does function unknown to traverse the tree with root node pointed by the pointer r? a. preorder b. inorder c. postorder d. level order e. None of the above (2) Consider the following binary tree. After the execution of function unknown(r), what is the value of the data of the rightmost node. a. 7 b. 6 c. 3 d. 2 e. None of the above 20 / \ 18 15 / \ / \ 13 12 10 11 \ / \ / \ / \ 3 6 7 2 4 5 9 交大給的答案分別為C E 我看不太懂所以想說要問一下大家 沒錯的話unknown應該是SWAP吧?? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.171.116.24

02/20 01:46, , 1F
swap沒錯 所以第二題 最右邊是13
02/20 01:46, 1F

02/20 01:50, , 2F
但第一題好像有點問題
02/20 01:50, 2F
第一題我考試時看成他是問unknown(r)是什麼運算 不過剛剛打題目才發現我看錯題目的意思 不過我反而看不懂第一題問什麼了... 第二題我當初也想了很久 不知道怎麼寫 最後是想說如果存到陣列來看最右就是3 而在那邊不知道選哪個定義好 看來老師是採13那邊當最右 或最右就是NULL... ※ 編輯: AirJordan 來自: 118.171.116.24 (02/20 01:55) ※ 編輯: AirJordan 來自: 118.171.116.24 (02/20 01:56)

02/20 06:49, , 3F
我考時也沒看清楚第一題選了e...Q__Q
02/20 06:49, 3F

02/20 11:03, , 4F
第一題我也想說是SWAP然後就選E...
02/20 11:03, 4F

02/20 21:54, , 5F
我也選E..
02/20 21:54, 5F
文章代碼(AID): #1FGJANv9 (Grad-ProbAsk)