#include<stdio.h>
#include<stdio.h>
#include<stdlib.h>
struct bst
{
struct bst *left;
int info;
struct bst *right;
};
struct bst root;
void create(struct bst*,int);
void preorder(struct bst*);
void postorder(struct bst*);
void del_leaf();
void del_singlechild():
void main()
{
struct bst *p;
int n,c;
char ch;
root=(struct bst*)malloc(sizeof(struct bst));
printf("\nenter the info:");
scanf("%d",&root->info);
root->left=root->right=NULL;
do
{
 printf("\ndo you wish to continue:");
 ch=getch();
 if(ch=='y')
 {
 p=root;
 printf("\nenter the info:");
 scanf("%d",&n);
 create(p,n);
 }
 }
 while(ch!='n');
do
{
 printf("\n1. preorder");
 printf("\n2. inorder");
 printf("\n4. postorder");
 printf("\n5. delete a leaf node");
 printf("\n6. exit");
 printf("\nenter choice");
 scanf("%d",&c);
 switch(c)
 {
 case 1: preorder(root);
	  break;
 case 2: inorder(root);
	  break;
 case 3: postorder(root);
	  break;
 case 4: del_leaf();
	  break;
 case 5: exit(0);
 }
 }while(c!=6);
}
 void create(struct bst*p,int n)
 {
 struct bst *q;
  if(n=p->info)
  {
  printf("\nduplicate value");
  return;
 }
  else if(n<p->info)
  {
  if(p->left!=null)
     create(p->left,n);
  else
  {
  q=(struct bst*)malloc(sizeof(struct bst));
  q->info=n;
  q->left=q->right=null;
  p->left=q;
  }
 }
}
  if(p->right!=NULL)
     create(p->right,n);
     else
     {
  q=(struct bst*)malloc(sizeof(struct bst));
  q->info =n;
  q->left=q->right=NULL;
  p->right=q;
  }
 }
}
  void preorder(struct bst* root)
  {
  struct bst *p;
  p=root;
  if(p!=NULL)
  {
  inorder(p->left);
  printf("\t%d",p->info);
  }
  }

  void postorder(struct bst *root)
  {
  struct bst *p;
  p=root;
  if(p!->left);
  postorder(p->right);
  printf("\t%d",p->info);
  }
  }

void del_leaf()
{
int n;
struct bst *ptr,*par;
printf("n\enter the value of leaf node to delete:");
scanf("%",&n);
par=ptr=root;
while(ptr->info!=n)
{
     if(ptr->info<n)
       {
	par=ptr;
	ptr=ptr->right;

	}
     else
     {
      par=ptr;
      ptr=ptr->left;
      }
}
      if(ptr->info<par->info)
	 par->left=NULL;
	else
	   par->right=NULL;

	free(ptr);
}

void del_singlechild()
{
int n;
struct bst *ptr,*par,*child,
printf("/enter the value of leaf node to delete:");
scanf("%d",&n);
par=ptr=root;

while(ptr->info=n)
{
      par=ptr;
      ptr=ptr->right

   }
   else
   {
    par=ptr;
    ptr=ptr->left;
    }
}

    if(ptr->left==null)
	 child=ptr->riht;
      else
      child=ptr->left;

    if(ptr->info(par->info)
       par->left=child;
      else
       par->right=child;
       free(ptr);
}

I AM USING TURBO C To Write This Programe & i got 20 error every thing i writed perfect but donno how to make it work today is my pratical of this progrrame pizz make it work :(

Look at line 15.

void del_singlechild():

Your using a : and not a ;

You define

struct bst root;

and here your allocating memory for it

root=(struct bst*)malloc(sizeof(struct bst));

Why?

error 20 to 25 :P

@gerard4143 sir i am a starter pizz make it correct :(

#include<stdio.h>
#include<stdio.h>
#include<stdlib.h>
struct bst
{
struct bst *left;
int info;
struct bst *right;
};
struct bst root;
void create(struct bst*,int);
void preorder(struct bst*);
void inorder(struct bst*);
void postorder(struct bst*);
void del_leaf();
void del_singlechild();
void main()
{
struct bst *p;
int n,c;
char ch;
root=(struct bst*)malloc(sizeof(struct bst));
printf("\nenter the info:");
scanf("%d",&root->info);
root->left=root->right=NULL;
do
{
 printf("\ndo you wish to continue:");
 ch=getch();
 if(ch=='y')
 {
 p=root;
 printf("\nenter the info:");
 scanf("%d",&n);
 create(p,n);
 }
 }while(ch!='n');
 do
 {
 printf("\n1. preorder");
 printf("\n2. inorder");
 printf("\n3. postorder");
 printf("\n4. delete a leaf node");
 printf("\n5. delete a node having single child");
 printf("\n6. exit");
 printf("\nenter choice");
 scanf("%d",&c);
 switch(c)
 {
 case 1:preorder(root);
	 break;
 case 2:inorder(root);
	 break;
 case 3:postorder(root);
	 break;
 case 4:del_leaf();
	 break;
 case 5:exit(0);
 }
 }while(c!=5);
}
 void create(struct bst*p,int n)
 {
 struct bst *q;
  if(n=p->info)
  {
  printf("\nduplicate value");
  return;
 }
  else if(n<p->info)
  {
  if(p->left!=NULL)
     create(p->left,n);
  else
  {
  q=(struct bst*)malloc(sizeof(struct bst));
  q->info=n;
  q->left=q->right=NULL;
  p->left=q;
  }
 }
}
  if(p->right!=NULL)
     create(p->right,n);
     else
     {
  q=(struct bst*)malloc(sizeof(struct bst));
  q->info=n;
  q->left=q->right=NULL;
  p->right=q;
  }
 }
}
  void preorder(struct bst* root)
  {
  struct bst *p;
  p=root;
  if(p!=NULL)
  {
  printf("\t%d",p->info);
  preorder(p->left);
  preorder(p->left);
  }
  }

  void inorder(struct bst *root)
  {
  struct bst *p;
  p=root;
  if(p!=NULL)
  {
  if(p!->left);
  postorder(p->right);
  printf("\t%d",p->info);
  inorder(p->order)
  }
  }
  void postorder(struct bst *root)
  {
  struct bst *p;
  p=root;
  if(p!=NULL)
  {
  postorder(p->left);
  postorder(p->right);
  printf("\t%d",p->info);
  }
  }
void del_leaf()
{
int n;struct bst *ptr,*par;
printf("\nenter the value of leaf node to delete":);
scanf("%d",&n);
par=ptr=root;

while(ptr->info!=n)
{
     if(ptr->info!=n)
       {
       par=ptr;
       ptr=ptr->right;

    }
  else
  }
       par=ptr;
       ptr=ptr->left;
       }
 }
    if(ptr->info<par->info)
	    par->left=NULL;
  else       par->right=null;

      free(ptr);

  }
  void del_singlechild()
  {
  int n;
  struct bst *ptr,*par,*child;
  printf("\nenter the value of leaf of leaf node to delete:");
  scanf("%d",&n);
  par=ptr=root;

  while(ptr->info=n)
  {

  par=ptr;
  ptr=ptr->right;

  }
  else
  {
  par=ptr;
  ptr=ptr->left;
  }
}
  if(ptr->left==NULL)
    child=ptr->right;
 else
    child=ptr->right;
 if(ptr->info(par->info)
    par->left=child;
 else
    par->right=child;
  free(ptr);
}

NOW THESE ARE ERRORS

22: ILLEGAL STRUCTURE OPARETION
24: PIONTER TO STRUCTURE REQUIRED ON LEFT SIDE OF ->OR->*
25: PIONTER TO STRUCTURE REQUIRED ON LEFT SIDE OF ->OR->*
25: PIONTER TO STRUCTURE REQUIRED ON LEFT SIDE OF ->OR->*
32: ILLEGAL STRUCTURE OPERATION
50: TYPE MISSMATCH IN PARAMETRE 1 IN CALL TO "PREORDER"
52: TYPE MISSMATCH IN PARAMETRE 1 IN CALL TO "INORDER"
54: TYPE MISSMATCH IN PARAMETRE 1 IN CALL TO "POSTORDER:
65: POSSIBLY INCORRECT ASSIGNMENT
83: DECLARATION TERMINATED INCORRECTLY
85: DECLARATION TERMINATED INCORRECTLY
92: UNEXPECTED }
93: UNEXPECTED }
112: IF STATEMENT IS MISSING )
115: UNDEFINED SYMBOL 'ORDER'
116: STATEMENT MISSING ;
118: DECLARARTION IS NOT ALLOWED HERE
119: DECLARATION SYNTAX ERROR
149: DECLARATION IS MISING ;
150: DECLARATON TERMINATED INCORREECTLY
152: DECLARATON TERMINATED INCORREECTLY
154: TYPE MISMATCH IN REDECLARATION OF 'FREE'
154: DECLARATION WAS EXPECTED
156: DECLARATION WAS EXPECTED
156: TYPE MISMATCH IN PARAMETRE 'PTR'
156: FUNCTION SHOULD RETURN A VALUE
156: PARAMETRE 'PTR' IS NEVER USED
163: ILLEGAL SUTRUCTURE OPERATION
163: TWO MANY ERROR MASSAGES OR WARNING MASSAGE


I AM USING TURBO C To Write This Programe & i got 25 error every thing i writed perfect but donno how to make it work today is my pratical of this progrrame pizz make it work :2

I AM USING TURBO C To Write This Programe

I think You should get another compiler, may be pelles C or Code::Blocks or any other, whichever you like and feel comfortable to use.

@gerard4143 sir i am a starter pizz make it correct

If you're a starter ,IMHO you should start with something small.In this code you're just making some general syntax errors like gerard pointed out earlier- using colons instead of semi-colons,or using braces when there is no need of it or using it the wrong way

else
}
par=ptr;
ptr=ptr->left;
}

etc.

commented: And by getting a 'better compiler' he fails the class. Great idea! :( -4

Thanks for the bad reps WaltP! You're awesome!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.