Skip to content

Instantly share code, notes, and snippets.

@shemul
Created November 18, 2014 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shemul/6911b7c663aca9b18e75 to your computer and use it in GitHub Desktop.
Save shemul/6911b7c663aca9b18e75 to your computer and use it in GitHub Desktop.
FUNC BST
#ifndef FUNC_H_INCLUDED
#define FUNC_H_INCLUDED
#include <iostream>
using namespace std;
typedef struct TreeLeaves
{
int fruit ;
struct TreeLeaves *leftFruit ,*rightFruit;
}*Tleaf ;
Tleaf makeThetree (Tleaf p , int fruitName )
{
if(p==NULL)
{
p= new(TreeLeaves);
p->fruit = fruitName ;
p->leftFruit = NULL ;
p->rightFruit = NULL;
}
else if(fruitName < p->fruit)
{
p->leftFruit= makeThetree(p->leftFruit,fruitName);
}
else if(fruitName > p->fruit)
{
p->rightFruit = makeThetree(p->rightFruit,fruitName);
}
return p ;
}
void inOrder(Tleaf N)
{
if(N!=NULL)
{
inOrder(N->leftFruit);
cout<<N->fruit << " " ;
inOrder(N->rightFruit);
}
}
void postOrder(Tleaf N)
{
if(N!=NULL)
{
postOrder(N->leftFruit);
postOrder(N->rightFruit);
cout<<N->fruit << " " ;
}
}
void preOrder(Tleaf N)
{
if(N!=NULL)
{
cout<<N->fruit << " " ;
postOrder(N->leftFruit);
postOrder(N->rightFruit);
}
}
int searchInTree(Tleaf N , int x)
{
if(N==NULL)
{
return 1 ;
}
else
{
if(x > N->fruit)
{
searchInTree(N->rightFruit,x);
}
else if(x< N->fruit)
{
searchInTree(N->leftFruit,x);
}
// cout << N->fruit ;
else
cout<<"FOUND"<< endl;
}
}
void DrawTheTree(Tleaf N)
{
}
#endif // FUNC_H_INCLUDED
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment