void pre_order_travelse(btree_node* root) { if(root != NULL) { printf("%c-", ((struct node*)root)->v); pre_order_travelse(root->left); pre_order_travelse(root->right); } }
void mid_order_travelse(btree_node* root) { if(root != NULL) { mid_order_travelse(root->left); printf("%c-", ((struct node*)root)->v); mid_order_travelse(root->right); } }遍历效果:
void post_order_travelse(btree_node* root) { if(root != NULL) { post_order_travelse(root->left); post_order_travelse(root->right); printf("%c-", ((struct node*)root)->v); } }
void level_order_travelse(btree_node* root) { if(root != NULL) { LinkQueue* queue = LinkQueue_Create(); if(queue != NULL) { LinkQueue_Append(queue, root); while( LinkQueue_Length(queue) > 0) { struct node* node = (struct node*)LinkQueue_Retrieve(queue); printf("%c, ", node->v); LinkQueue_Append(queue, node->header.left); LinkQueue_Append(queue, node->header.right); } } LinkQueue_Destroy(queue); } }
原文地址:http://blog.csdn.net/u011467781/article/details/45271359