473,403 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

a binary tree error

14
hi
i wrote a binary search program in c++ using classes.but it is showing the errors that is type name expected,declaration terminated incorrectly.
please help me.
Oct 15 '07 #1
6 1319
Ganon11
3,652 Expert 2GB
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).
Oct 15 '07 #2
sai124
14
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 "declaration terminated incorrectly"

<MODERATOR NOTE: Code is below. This thread is a bit messy due to some weird forum errors.>
Oct 15 '07 #3
Ganon11
3,652 Expert 2GB
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.
Oct 15 '07 #4
sai124
14
Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <iostream>
  3. template <class t>
  4. class bintree
  5. {
  6.   struct bst
  7.   {
  8.    t data;
  9.    struct bst *left,*right;
  10.   }*root,*nn,*temp;
  11.  
  12. public:
  13.    bintree()
  14.    {
  15.      root=NULL;
  16.    }
  17. void create();
  18. void insert(node (*root),node (*nn));
  19. void inorder(node (*temp));
  20. };
  21. template<class t>
  22. void bintree <t>:: create()
  23. {
  24.  
  25.   nn=new node;
  26.   nn->left=NULL;
  27.   nn->right=NULL;
  28.   cout<<"Enter the element\n ";
  29.   cin>>nn->data;
  30.  
  31.   if(root==NULL)
  32.      root=nn;
  33.   else
  34.     insert(root,nn);
  35. }
  36. void bintree <t>:: inorder(node *temp)
  37. {
  38.    if(temp!=NULL)
  39.    {
  40.      inorder(temp->left);
  41.      cout<<"  "<<temp->data;
  42.      inorder(temp->right);
  43.    }
  44. }
  45. template <class t>
  46. void bintree <t>:: insert(node *root,node *nn)
  47. {
  48.   if(nn->data<root->data)
  49.   {
  50.       if(root->left==NULL)
  51.              root->left=nn;
  52.       else
  53.           insert(root->left,nn);
  54.   }
  55.   if(nn->data>root->data)
  56.   {
  57.        if(root->right==NULL)
  58.               root->right=nn;
  59.        else
  60.          insert(root->right,nn);
  61.   }
  62. }
  63. void main()
  64. {
  65.  bintree <int> bst;
  66.  int ch;
  67.  while(ch<=3)
  68.  {
  69.    cout<<"1.create\n2.insert\n3.inorder";
  70.    cout<<"\n Enter the choice";
  71.    cin>>ch;
  72.    switch(ch)
  73.    {
  74.      case 1:bst.create();
  75.             break;
  76.      case 2:bst.insert();
  77.             break;
  78.      case 3:bst.inorder();
  79.             break;
  80.    }
  81.   }
  82. }
  83.  
Oct 15 '07 #5
Ganon11
3,652 Expert 2GB
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.
Oct 15 '07 #6
sai124
14
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 "declaration 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.
Oct 15 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jerry Khoo | last post by:
hello, everybody, i am kinda new here, nice to meet u all. Now, i am > cs students and are now facing difficult problems in understanding > what a binary tree is, how it works, and the algorithm...
4
by: Tarique Jawed | last post by:
Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working,...
4
by: sun6 | last post by:
this is a program counting words from "text_in.txt" file and writing them in "text_out.txt". it uses binary tree search, but there is an error when i use insert () thanks for any help ...
5
by: pembed2003 | last post by:
Hi, I have a question about how to walk a binary tree. Suppose that I have this binary tree: 8 / \ 5 16 / \ / \ 3 7 9 22 / \ / \ / \
15
by: Foodbank | last post by:
Hi all, I'm trying to do a binary search and collect some stats from a text file in order to compare the processing times of this program (binary searching) versus an old program using linked...
1
TMS
by: TMS | last post by:
I'm trying to write an address book that is based on a binary tree. I'm devloping in Visual C++ (I blew up my Ubuntu with the new dist, so no EMACS), starting with the basics: #ifndef...
1
by: hn.ft.pris | last post by:
I have the following code: Tree.h defines a simple binary search tree node structure ########## FILE Tree.h ################ #ifndef TREE_H #define TREE_H //using namespace std; template...
20
by: DemonFox | last post by:
i have started my midterm exersize than is on binary treescan anyone help me on the basics i have started and i have made the following on my tree.h file: struct treenode { int data;...
7
by: Vinodh | last post by:
Started reading about Binary Trees and got the following questions in mind. Please help. Definition of a Binary Tree from "Data Structures using C and C++ by Tanenbaum" goes like this, "A...
2
by: cioccolatina | last post by:
Hey guys, is there anyone who could help me..? I have file ExpressionBinaryTree.java : /** class ExpressionBinaryTree * uses a binary tree to represent binary expressions * does not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.