| ||||||||||
Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求教大牛,我的bst为什么new不到空间?我的bst如下,调试发现root总是NULL?为什么? #include <iostream> using namespace std; struct Node { Node *lc,*rc; int data; }; Node * root=NULL; void insert(Node * root,int num) { if(root==NULL) { root=new Node; root->data=num; root->lc=NULL; root->rc=NULL; return ; } if(num>root->data) insert(root->rc,num); else insert(root->lc,num); } void output(Node * root) { if(root==NULL) return; output(root->lc); output(root->rc); printf("%d ",root->data); } int main() { int input; while(scanf("%d",&input),input!=0) { insert(root,input); } output(root); printf("\n"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator