十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
#include#include /* 递归前中后遍历 */ typedef struct node { int data; struct node*left; struct node*right; }BTnode; BTnode* CreateTree(BTnode* root,int x) { if(!root) //如果root结点为空,创建叶子结点 { root = (BTnode*)malloc(sizeof(BTnode)); root->data = x; root->left=root->right=NULL; }else { if(root->data>x) root->left = CreateTree(root->left,x); //递归调用左 else if(root->data right = CreateTree(root->right,x);//递归调用右 } return root; } void Forder(BTnode*root) { if(root) { printf("%d",root->data); printf("\n"); Forder(root->left); Forder(root->right); } } void Inorder(BTnode*root) { if(root) { Inorder(root->left); printf("%3d",root->data); printf("\n"); Inorder(root->right); } } void Porder(BTnode*root) { if(root) { Porder(root->left); Porder(root->right); printf("%6d",root->data); printf("\n"); } } int main(void) { BTnode * head = NULL; int x; int n; int i; printf("请输入n="); scanf("%d",&n); printf("请输入二叉树的结点data\n"); for(i=0;i
当前标题:二叉排序树创建(递归)
转载源于:http://6mz.cn/article/pgddoh.html