Pointer to structure required on left side

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lyhour
    New Member
    • May 2014
    • 2

    Pointer to structure required on left side

    Code:
    #include<conio.h>
    #include<alloc.h>
    #include<string.h>
    struct node
    	{ int info;
         struct node *l;
         struct node *r;
       } *node;
    typedef struct node *pt;
    void freenode( pt p)
    	{ freenode(p);}
    pt getnode()
    	{ pt p;
         p=(struct node*)malloc(sizeof(struct node));
         return(p);
       }
    void ini (pt *proot)
    	{ proot=NULL;}
    pt makenode(int item)
    	{ pt p=getnode();
         p->info=item;
         p->l=NULL;
         p->r=NULL;
         return (p);
       }
    void makeleft (pt p,int item)
    	{ if(p==NULL)
       		printf("node p is NULL");
         else
         		{ if(p->l==NULL)
             	p->l=makenode(item);
               else
               	printf("node p has left son node");
             }
       }
    void makeright(pt p,int item)
    	{  if(p==NULL)
       		printf("node p is NULL");
         else
         		{ if(p->r==NULL)
             	p->r=makenode(item);
               else
               	printf("node p has right son node");
             }
         }
    void insert(pt proot, int item)
    	{ pt p;
         if(proot==NULL)
         	{	p=getnode();
          	p->info=item;
             p->l=NULL;
             p->r=NULL;
             proot=p;
          }
         else
         	{ if(item==p->info)
          	printf("it has already");
            else if (p->info>item)
            	insert(p->l,item);
            else
            	insert(p->r,item);
          }
       }
    pt del(pt p)
    	{ pt px,f;
         if (p==NULL)
         		return (NULL);
         else if (p->l==NULL&&p->r==NULL)
         		px=NULL;
         else if(p->l==NULL)
         		px=p->r;
         else if(p->r==NULL)
         		px=p->l;
         else
         	{ f=p;
            px=p->r;
            while(p->l!=NULL)
            {	f=px;
            		px=px->l;
            }
          }
         if(f!=p)
            { f->l=px->r;
            	 px->r;p->r;
              px->l;p->l;
            }
         else
         		px->l=p->l;
         freenode(p);
         return(px);
       }
    void display (pt *tree,int level)
    	{ int i;
         if(tree!=NULL)
         	{	display(tree->r,level+1);
          	printf("\n");
             for (i=0;i<level;i++)
             	printf("  ");
             printf("%d",tree->item);
             display(tree->l,level+1);
          }
       }
  • lyhour
    New Member
    • May 2014
    • 2

    #2
    To everyone please help me for this code , Thank in advance

    Comment

    • techboy
      New Member
      • Apr 2014
      • 28

      #3
      which line you getting error and what error you got ?

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        This code:
        Code:
        void display (pt *tree,int level)
             { int i;
             if(tree!=NULL)
                  {    display(tree->r,level+1);
             etc...
        shows tree at a pt*. pt itself is a node* so this is really a node** for tree. What you really need is just a node*.

        Therefore, change your function argument from pt* to pt and the pointer to structure on left side will disappear.

        There are other errors, but this will get you started.

        Comment

        Working...