Can someone help me out with this please?

I'm having trouble with this.... the traversing of the trees are so wrong... and i can't find the answer...

#include<iostream>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
struct node
{
int data;
node *left;
node *right;
};

node *tree=NULL;
node *insert(node *tree,int ele);

void preorder(node *tree);
void inorder(node *tree);
void postorder(node *tree);
int count=1;

int main()
{
system("cls");
int ch,ele;
char cho;
do

{
system("cls");
int t;
cout<<"\n\tPLEASE ENTER A NUMBER: ";
cin>>t;
cout<<"\n\tENTER THE ELEMENT "<<t<<" TIMES\n\t";
for(int c=0; c<t; c++)
{
cin>>ele;
cout<<"\t";
tree=insert(tree,ele);
}
cout<<"\n\t1----PRE-ORDER TRAVERSAL.";
cout<<"\n\t2----IN-ORDER TRAVERSAL.";
cout<<"\n\t3----POST-ORDER TRAVERSAL.";
cout<<"\n\t4----EXIT.";
cout<<"\n\tENTER CHOICE::";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\n\t****PRE-ORDER TRAVERSAL OF A TREE****\n\t";
preorder(tree);
break;

case 2:
cout<<"\n\t****IN-ORDER TRAVERSAL OF A TREE****\n\t";
inorder(tree);
break;

case 3:
cout<<"\n\t****POST-ORDER TRAVERSAL OF A TREE****\n\t";
postorder(tree);
break;

case 4:
exit(0);
}
cout<<"\n\t DO YOU WANT TO TRY AGAIN?[Y/N] : ";
cin>>cho;
}while(cho=='Y' || cho=='y');
system("cls");
cout<<"\n\t\t THANK YOU FOR USING THIS PROGRAM!!";
system("pause > 0");
}

node *insert(node *tree,int ele)
{
if(tree==NULL)
{
tree=new node;
tree->left=tree->right=NULL;
tree->data=ele;
count++;
}
else
if(count%2==0)
tree->left=insert(tree->left,ele);
else
tree->right=insert(tree->right,ele);
return(tree);
}

void preorder(node *tree)
{
if(tree!=NULL)
{
cout<<tree->data;
preorder(tree->left);
preorder(tree->right);
}
}

void inorder(node *tree)
{
if(tree!=NULL)
{
inorder(tree->left);
cout<<tree->data;
inorder(tree->right);
}
}

void postorder(node *tree)
{
if(tree!=NULL)
{
postorder(tree->left);
postorder(tree->right);
cout<<tree->data;
}
}




Do you have any idea what the problem is?
Topic archived. No new replies allowed.