i am getting the message execution timed out for the following code ....somebody please help to resolve it | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

i am getting the message execution timed out for the following code ....somebody please help to resolve it

#include<stdio.h> #include<malloc.h> struct node { int data; struct node *lchild; struct node *rchild; }; struct node* newnode(struct node *r,int k); void inorder(struct node *r); struct node *findpos(struct node *r,struct node *p); int main() { int n,i,k; struct node *root; root=NULL; printf("Enter n : "); scanf("%d",&n); for(i=0;i<n;i++) { printf("\n enter value : "); scanf("%d",&k); root=newnode(root,k); } printf("\n\n\n printing in order : \n"); inorder(root); return 0; } struct node* newnode(struct node *r,int k) { struct node *p; p=(struct node*)malloc(sizeof(struct node)); p->data=k; p->lchild=NULL; p->rchild=NULL; if(r==NULL) r=p; else r=findpos(r,p); return r; } void inorder(struct node *r) { if(r!=NULL) {inorder(r->lchild); printf("%d ",r->data); inorder(r->rchild); } } struct node *findpos(struct node *r,struct node *p) { struct node *c=r; while(r!=NULL) { if((r->data)>(p->data)) { if((r->lchild)==NULL) r->lchild=p; r=r->lchild; } else { if((r->rchild)==NULL) r->rchild=p; r=r->rchild; } } return c; }

12th Nov 2017, 5:02 PM
Gokul Krishna
Gokul Krishna - avatar
1 Answer
0
There is a limit to how much processing time your program is allowed in this code playground. Put some debugging console output to see how far you're getting (cout or printf.)
12th Nov 2017, 6:34 PM
John Wells
John Wells - avatar