a binary tree error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sai124
    New Member
    • Oct 2007
    • 14

    a binary tree error

    hi
    i wrote a binary search program in c++ using classes.but it is showing the errors that is type name expected,declar ation terminated incorrectly.
    please help me.
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    We can't help you unless you can give us some more information. What exactly are the errors you are getting, and can we see your code? (Please make sure you wrap them in [CODE] tags - if you don't know what these are, please refer to this section in our FAQ).

    Comment

    • sai124
      New Member
      • Oct 2007
      • 14

      #3
      Originally posted by Ganon11
      We can't help you unless you can give us some more information. What exactly are the errors you are getting, and can we see your code? (Please make sure you wrap them in [CODE] tags - if you don't know what these are, please refer to this section in our FAQ).

      this is my program i cant get ans.
      the errors are"type name is expected" and "declaratio n terminated incorrectly"

      <MODERATOR NOTE: Code is below. This thread is a bit messy due to some weird forum errors.>
      Last edited by Ganon11; Oct 15 '07, 03:49 PM. Reason: Please use the [CODE] tags provided.

      Comment

      • Ganon11
        Recognized Expert Specialist
        • Oct 2006
        • 3651

        #4
        sai124;

        It seems that, for some reason, our forums aren't letting your code appear. I'll contact the site administrators and let them know about the problem.

        Comment

        • sai124
          New Member
          • Oct 2007
          • 14

          #5
          [CODE=cpp]

          #include <iostream>
          template <class t>
          class bintree
          {
          struct bst
          {
          t data;
          struct bst *left,*right;
          }*root,*nn,*tem p;

          public:
          bintree()
          {
          root=NULL;
          }
          void create();
          void insert(node (*root),node (*nn));
          void inorder(node (*temp));
          };
          template<class t>
          void bintree <t>:: create()
          {

          nn=new node;
          nn->left=NULL;
          nn->right=NULL;
          cout<<"Enter the element\n ";
          cin>>nn->data;

          if(root==NULL)
          root=nn;
          else
          insert(root,nn) ;
          }
          void bintree <t>:: inorder(node *temp)
          {
          if(temp!=NULL)
          {
          inorder(temp->left);
          cout<<" "<<temp->data;
          inorder(temp->right);
          }
          }
          template <class t>
          void bintree <t>:: insert(node *root,node *nn)
          {
          if(nn->data<root->data)
          {
          if(root->left==NULL)
          root->left=nn;
          else
          insert(root->left,nn);
          }
          if(nn->data>root->data)
          {
          if(root->right==NULL)
          root->right=nn;
          else
          insert(root->right,nn);
          }
          }
          void main()
          {
          bintree <int> bst;
          int ch;
          while(ch<=3)
          {
          cout<<"1.create \n2.insert\n3.i norder";
          cout<<"\n Enter the choice";
          cin>>ch;
          switch(ch)
          {
          case 1:bst.create();
          break;
          case 2:bst.insert();
          break;
          case 3:bst.inorder() ;
          break;
          }
          }
          }
          [/CODE]

          Comment

          • Ganon11
            Recognized Expert Specialist
            • Oct 2006
            • 3651

            #6
            If this is C++, then you don't need the struct keyword in from of the left and right members of bst. Also, you declare this struct as bst, but I see some references in your code to a nonexistant struct/class called node. Maybe you should rename your struct BinaryNode or something appropriate.

            Comment

            • sai124
              New Member
              • Oct 2007
              • 14

              #7
              Originally posted by Ganon11
              If this is C++, then you don't need the struct keyword in from of the left and right members of bst. Also, you declare this struct as bst, but I see some references in your code to a nonexistant struct/class called node. Maybe you should rename your struct BinaryNode or something appropriate.
              i changed bst as node.
              but what is "declaratio n terminated incorrectly" it is the error.is there any error un main function?it is showing in main function.what is meaning of that error.

              Comment

              Working...