Posts

Showing posts from November, 2017

Binary Search Tree Mirror Image creation......

/*Binary Search Tree with Mirror Image Conversion of the original Tree ... */ #include<stdio.h> #include<stdlib.h> typedef struct BinarySearchTree { struct BinarySearchTree *left; struct BinarySearchTree *right; int val; }bst; typedef struct Queue { bst *val; struct Queue *next; }qu; void enqueu(qu **,bst *); bst *dequeu(qu **); int isempty(qu *); bst * create(bst *,int); void inorder(bst *); void preorder(bst *); void postorder(bst *); void levelorder(bst *); void mirimg(bst *); int main() { bst *root=NULL; int g,ch; while(1) { printf("\n\n 1) Insert\n 2) Preorder traversal\n 3) Inorder traversal\n 4) Postorder traversal\n 5) Level Order Traversal\n 6) Construct Mirro Image of the tree\n 7) Exit"); printf("\n\n Enter your choice : "); scanf("%d",&ch); switch(ch) { case 1: printf("\nInsert value for the tree: "); scanf("%d",&g); root=create(root,g); break; c

Binary Search Tree With Level Order Traversal

Image
/*Binary Search Tree with level order traversal ... Queue for level order traversal is implemented using linked list*/ #include<stdio.h> #include<stdlib.h> typedef struct BinarySearchTree { struct BinarySearchTree *left; struct BinarySearchTree *right; int val; }bst; typedef struct Queue { bst *val; struct Queue *next; }qu; void enqueu(qu **,bst *); bst *dequeu(qu **); int isempty(qu *); bst * create(bst *,int); void inorder(bst *); void preorder(bst *); void postorder(bst *); void levelorder(bst *); int main() { bst *root=NULL; int g,ch; while(1) { printf("\n 1) Insert\n 2) Preorder traversal\n 3) Inorder traversal\n 4) Postorder traversal\n 5) Level Order Traversal\n 6) Exit"); printf("\n Enter your choice : "); scanf("%d",&ch); switch(ch) { case 1: printf("\nInsert value for the tree: "); scanf("%d",&g); root=create(root,g); break; case 2: printf("\nValues in