首页 > 代码库 > Q114第一颗二叉查找树(链式)
Q114第一颗二叉查找树(链式)
输入n,然后n个树,建立二叉查找树。从小到大输出每个节点的左右子树,空输出#
#include<cstdio> #include<iostream> using namespace std; typedef struct node{ int data; struct node *lchild,*rchild; }NODE; void input(NODE *root,int value){ if(value=http://www.mamicode.com/=root->data){"%d(",root->data); if(root->lchild==NULL){ printf("#"); } else{ printf("%d",root->lchild->data); } if(root->rchild==NULL){ printf(", #)\n"); } else{ printf(", %d)\n",root->rchild->data); } count++; } preorder(root->rchild); } int main(){ NODE *root=new NODE; root->lchild=root->rchild=NULL; int a; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d",&a); input(root,a); } preorder(root); return 0; }
Q114第一颗二叉查找树(链式)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。