6 Replies - 469 Views - Last Post: 22 September 2011 - 10:28 AM Rate Topic: -----

#1 rock_star  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 9
  • Joined: 17-September 11

binary search tree ''code progrrame'' in data sutructu

Posted 22 September 2011 - 07:08 AM

#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 to is tommorw is my pratical of this progrrame pizz make it work

Is This A Good Question/Topic? 0
  • +

Replies To: binary search tree ''code progrrame'' in data sutructu

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 4068
  • View blog
  • Posts: 12,549
  • Joined: 25-December 09

Re: binary search tree ''code progrrame'' in data sutructu

Posted 22 September 2011 - 07:11 AM

Post the complete error messages exactly as they appear in your development environment.

Jim
Was This Post Helpful? 0
  • +
  • -

#3 rock_star  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 9
  • Joined: 17-September 11

Re: binary search tree ''code progrrame'' in data sutructu

Posted 22 September 2011 - 07:27 AM

View Postjimblumberg, on 22 September 2011 - 07:11 AM, said:

Post the complete error messages exactly as they appear in your development environment.

Jim

ok sir give me 20 minutes
Was This Post Helpful? 0
  • +
  • -

#4 rock_star  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 9
  • Joined: 17-September 11

Re: binary search tree ''code progrrame'' in data sutructu

Posted 22 September 2011 - 09:28 AM

#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

This post has been edited by rock_star: 22 September 2011 - 09:29 AM

Was This Post Helpful? 0
  • +
  • -

#5 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1343
  • View blog
  • Posts: 4,606
  • Joined: 19-February 09

Re: binary search tree ''code progrrame'' in data sutructu

Posted 22 September 2011 - 09:31 AM

You have created an object of the structure and not a pointer.
struct bst root;



In main though you use root as if it was a pointer

root=(struct bst*)malloc(sizeof(struct bst));
printf("\nenter the info:");
scanf("%d",&root->info);
root->left=root->right=NULL;


Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9196
  • View blog
  • Posts: 34,529
  • Joined: 12-June 08

Re: binary search tree ''code progrrame'' in data sutructu

Posted 22 September 2011 - 10:17 AM

@rock_star - watch out for creating erroneous duplicate threads.
Was This Post Helpful? 0
  • +
  • -

#7 jimblumberg  Icon User is offline

  • member icon


Reputation: 4068
  • View blog
  • Posts: 12,549
  • Joined: 25-December 09

Re: binary search tree ''code progrrame'' in data sutructu

Posted 22 September 2011 - 10:28 AM

In addition to what already informed you about you need to check your brace "{}" placement. Insure every opening brace has a closing brace. You seem to have at least one mismatch. You also seem to have some closing braces where an opening brace is called for.

Also note: The function main() should be defined to return an int, int main() and you should return an int to the operating system.

You should also consider finding a more modern compiler. Turbo-C is a couple of decades old and does not follow the current C/C++ standards.

Jim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1