|
|
back to boardWHY I GOT CE?? HeLp!! THIS IS MY CODE #include<stdio.h> #include<stdlib.h> typedef struct node { int val; struct node *l,*r; }NODE; void entree(NODE* p,int a) { if(a<p->val) { if(p->l==NULL) { p->l=(NODE*)malloc(sizeof(NODE)); p=p->l; p->val=a; p->l=p->r=NULL; } else entree(p->l,a); } else { if(p->r==NULL) { p->r=(NODE*)malloc(sizeof(NODE)); p=p->r; p->val=a; p->l=p->r=NULL; } else entree(p->r,a); } } void order(NODE *p) { if(p->r!=NULL) order(p->r); if(p->l!=NULL) order(p->l); printf("%d ",p->val); } void main() { NODE *first,*cur; int *ar,n; scanf("%d",&n); ar=(int *)malloc(sizeof(int)*n); for(int i=n-1;i>=0;i--) scanf("%d",ar+i); first=(NODE*)malloc(sizeof(NODE)); first->val=*ar; first->l=first->r=NULL; for(i=1;i<n;i++) { cur=first; entree(cur,*(ar+i)); } cur=first; order(cur); } ThAnKs FoR AdVaNcE Re: WHY I GOT CE?? HeLp!! Declare your i variable in the main function along with the other ints (*ar, n), not in the for, and you'll get AC. I don't know why this happens cause in my Visual C++ it works like that... Also you cand take a look at the errors by choosing send result to mail, as I've done with your source now... Re: WHY I GOT CE?? HeLp!! Thank YOUUU!! Very much ^o^ Re: WHY I GOT CE?? HeLp!! I think the problem was in the second loop "for": variable "i" was not declared... //---------------------------- for(i=1;i<n;i++) { cur=first; entree(cur,*(ar+i)); } //---------------------------- |
|
|