Created
November 18, 2014 10:48
-
-
Save shemul/6911b7c663aca9b18e75 to your computer and use it in GitHub Desktop.
FUNC BST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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