一種存資料的型態,由最初的節點延伸下多個分支,每個分支都個有個自的子分支,分支下可分割成彼此不相交的子集合,也稱為子樹。
由一個跟節點和兩個分支構成的樹,兩個分支一位置被稱為左子樹與右子樹,樹不可為空集合,二元樹可以,且有順序之分。
先略
    左兒子 資料 右兒子
      L    V    R
依照追蹤組合有六種:LVR、LRV、VLR、VRL、RVL、RLV
因追蹤有受先左再右,因此剩3種:LVR 、 LRV 、 VLR
void inorder(tree_pointer ptr)
/*中序追蹤 */
{
    if (ptr) {
L     inorder(ptr->left_child);       
V     printf(“%d”, ptr->data);      
R     inorder(ptr->right_child);  
    }
}
void preorder(tree_pointer ptr)
/* 前序追蹤 */
{
     if (ptr) {
V       printf(“%d”, ptr->data); 
L       preorder(ptr->left_child);       
R       preorder(ptr->right_child);  
     }
}
void postorder(tree_pointer ptr)
/* 後序追蹤 */
{
    if (ptr) {
L      postorder(ptr->left_child);       
R      postorder(ptr->right_child);  
V      printf(“%d”, ptr->data);
    }
}
void iter_inorder(tree_pointer node)
{
  int top= -1; /* 初始化堆疊 */
  tree_pointer stack[MAX_STACK_SIZE];
  for (;;) {
     for (; node; node = node->left_child)
         push(node);  /* 將節點加入堆疊 */
     node= pop();  /* 自堆疊刪除節點 */
     if (!node) break;  /* 空堆疊 */
     printf(“%d”, node->data);
     node = node->right_child;
  }
}
void level_order(tree_pointer ptr)
/* 階層次序追蹤 */
{
    int front = rear = 0;
    tree_pointer queue[MAX_QUEUE_SIZE];
    if (!ptr) return;   /* 空樹 */
    addq(ptr);
    for (;;) {
        ptr = deleteq();
        if (ptr) {
        printf (“%d”, ptr ->data);
        if (ptr ->left_child)
            addq(ptr ->left_child);
        if (ptr ->right_child)
            addq(ptr ->right_child);
        }
        else break;
    }
}