高考申論題
108年
[資訊處理] 資料結構
第 一 題
一、給予如下二元樹節點的宣告,分別寫出 C 的遞迴程式計算二元樹節點個數及計算二元樹葉節點(leaves)個數(Count the number of nodes in a binary tree and count the number of leaf nodes in a binary tree, respectively)。(25 分)
struct node{
int info;
struct node *left;
struct node *right;
}
typedef struct node *NODEPTR;
void countTree(NODEPTR tree){
}
void countLeaves(NODEPTR tree){
}
📝 此題為申論題
思路引導 VIP
- 辨識核心問題:本題要求實作二元樹的「遍歷與統計」。遞迴是解決樹狀結構問題最直觀的方法。
- 節點總數邏輯:一個樹的總節點數 = 根節點(1) + 左子樹節點數 + 右子樹節點數。基本案例(Base Case)是當樹為空(NULL)時,數量為 0。
🤖
AI 詳解
AI 專屬家教
【考點分析】 本題考查二元樹(Binary Tree)的遞迴遍歷(Recursive Traversal)應用,包含基礎節點統計與條件篩選(葉節點判斷)。 【理論/法規依據】
▼ 還有更多解析內容