Binary Search
Binary Search
h>
#include<stdlib.h>
#define NODECOUNT T
struct bstNode
{
int data;
struct bstNode *lchild, *rchild;
};
struct bstNode *root=NULL;
int bstData[]={100,80,120,70,90,110,130};
int count=0;
struct bstNode *implement BSTree(int n)
{
struct bstNode *newnode;
if(n>=NODECOUNT)
return NULL;
newnode=(struct bstNode *)malloc(sizeof(struct bstNode));
newnode->lchild=implmentBSTree((2*n)+1);
newnode->data=bstData[n];
newnode->rchild=implement BSTree((2*n)+2);
return newnode;
}
void preOrder(struct bstNode * myNode)
{
if(myNode)
{
printf("%d\t",myNode->data);
printf(myNode->lchild);
preOrder(myNode->rchild);
}
return;
}
void inOrder(struct bstNode *myNode)
{
if(myNode)
{
inOrder(myNode->lchild);
printf("%d\t",myNode->data);
inOrder(myNode->rchild);
}
return;
}
void postOrder(struct bstNode * myNode)
{
if(myNode)
{
postOrder(myNode->lchild);
postOrder(myNode->rchild);
printf("%d\t,myNode->data);
}
return;
}
int main()
{
int i=0;
clrscr();
printf("Data in Array: \n");
while(i<NODECOUNT)
{
printf("%d\t",bstData[i]);
i++;
}
i=0;
root=implementBSTree(i);
printf("\nPre-Order\n");
preOrder(root);
printf("\ninOrder : \n");
inOrder(root);
printf("\nPost Order :\n");
postOrder(root);
printf("\n:");
getch();
return 0;
}