Showing posts with label CS6311-PDS II LAB MANUAL. Show all posts
Showing posts with label CS6311-PDS II LAB MANUAL. Show all posts

Wednesday, February 24, 2016

DIJKSTRA’S ALGORITHM

AIM:
         To implement a C++ program for Dijkstra’s Algorithm to find the shortest path algorithm.
ALGORITHM:

Step 1: Include the header files
Step 2: Save the adjacency matrix in a file.
Step 3: Get as input the source node and destination node.
Step 4: Search the shortest path from source to destination.
Step 5: Initialize all the distances in the shortest path graph to infinity and all the  nodes status to infinity.
Step 6: Start with the source node.
Step 7: Find the adjacent node and its shortest distance from  the source node.
Step 8: Take the minimum distance value node and repeat step(7) till all the nodes become visited.

PROGRAM:

#include<iostream>
#define INFINITY 999
using namespace std;
class Dijkstra
{
   private:
       int adjMatrix[15][15];
       int predecessor[15],distance[15];
       bool mark[15];    //keep track of visited node
       int source;
       int numOfVertices;
   public:
       void read();
       void initialize();
        int getClosestUnmarkedNode();
       void calculateDistance();
       void output();
       void printPath(int);
};
void Dijkstra::read()
{
   cout<<"Enter the number of vertices of the graph(should be > 0)\n";
   cin>>numOfVertices;

   while(numOfVertices <= 0)
{
       cout<<"Enter the number of vertices of the graph(should be > 0)\n";
       cin>>numOfVertices;
   }
   cout<<"Enter the adjacency matrix for the graph\n";
   cout<<"To enter infinity enter "<<INFINITY<<endl;
   for(int i=0;i<numOfVertices;i++)
{
       cout<<"Enter the (+ve)weights for the row "<<i<<endl;
       for(int j=0;j<numOfVertices;j++)
{
           cin>>adjMatrix[i][j];
           while(adjMatrix[i][j]<0)
{
               cout<<"Weights should be +ve. Enter the weight again\n";
               cin>>adjMatrix[i][j];
           }
       }
   }
   cout<<"Enter the source vertex\n";
   cin>>source;
   while((source<0) && (source>numOfVertices-1))
{
       cout<<"Source vertex should be between 0 and"<<numOfVertices-1<<endl;
       cout<<"Enter the source vertex again\n";
       cin>>source;
   }
}
void Dijkstra::initialize()
{
   for(int i=0;i<numOfVertices;i++)
{
       mark[i] = false;
       predecessor[i] = -1;
       distance[i] = INFINITY;
   }
   distance[source]= 0;
}
int Dijkstra::getClosestUnmarkedNode()
{
   int minDistance = INFINITY;
   int closestUnmarkedNode;
   for(int i=0;i<numOfVertices;i++)
{
       if((!mark[i]) && ( minDistance >= distance[i]))
{
           minDistance = distance[i];
           closestUnmarkedNode = i
}
   }
   return closestUnmarkedNode;
}
void Dijkstra::calculateDistance()
{
   initialize();
   int minDistance = INFINITY;
   int closestUnmarkedNode;
   int count = 0;
   while(count < numOfVertices)
{
       closestUnmarkedNode = getClosestUnmarkedNode();
       mark[closestUnmarkedNode] = true;
       for(int i=0;i<numOfVertices;i++)
{
           if((!mark[i]) && (adjMatrix[closestUnmarkedNode][i]>0) )
{
               if(distance[i] > distance[closestUnmarkedNode]+adjMatrix[closestUnmarkedNode][i])
{
                   distance[i] = distance[closestUnmarkedNode]+adjMatrix[closestUnmarkedNode][i];
                   predecessor[i] = closestUnmarkedNode;
               }
           }
       }
       count++;
   }
}
void Dijkstra::printPath(int node)
{
   if(node == source)
       cout<<(char)(node + 97)<<"..";
   else if(predecessor[node] == -1)
       cout<<"No path from “<<source<<”to "<<(char)(node + 97)<<endl;
   else
{
       printPath(predecessor[node]);
       cout<<(char) (node + 97)<<"..";
   }
}

Tuesday, February 23, 2016

KRUSKAL’S ALGORITHM

AIM:
         To implement a C++ program for Kruskal’s Algorithm to find MST of an undirected graph.
ALGORITHM:
Step 1: Include the header files
Step 2: Get the number of vertices n, vertices and edges weight.
Step 3: Get the edge weights and place it in the priority queue in ascending order.
Step 4: Create a disjoint sets where each vertex will be separate disjoint set.
Step 5: Find the minimum value from the priority queue and its connecting vertices.
Step 6: Make a union of those vertices and mark the edges as accepted if it does not form a cycle in the  
            MST and delete the minimum from the priority queue.
Step 7: Repeat from step 3 till all the vertices are connected.

PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
using namespace std;
int cost[10][10],i,j,k,n,m,c,visit,visited[10],l,v,count,count1,vst,p;
main()
{
int dup1,dup2;
cout<<"enter no of vertices";
cin >> n;
cout <<"enter no of edges";
cin >>m;
cout <<"EDGE Cost";
for(k=1;k<=m;k++)
{
cin >>i >>j >>c;
cost[i][j]=c;
cost[j][i]=c;
}
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(cost[i][j]==0)
cost[i][j]=31999;
visit=1;
while(visit
{
v=31999;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(cost[i][j]!=31999 && cost[i][j]
{
int count =0;

for(p=1;p<=n;p++)
{
if(visited[p]==i || visited[p]==j)
count++;
}
if(count >= 2)
{
for(p=1;p<=n;p++)
if(cost[i][p]!=31999 && p!=j)
dup1=p;
for(p=1;p<=n;p++)
if(cost[j][p]!=31999 && p!=i)
dup2=p;
if(cost[dup1][dup2]==-1)
continue;
}
l=i;
k=j;
v=cost[i][j];
}
cout <<"edge from " <<<"-->"<
cost[l][k]=-1;
cost[k][l]=-1;
visit++;
int count=0;
count1=0;
for(i=1;i<=n;i++)
{
if(visited[i]==l)
count++;
if(visited[i]==k)
count1++;
}

Monday, February 22, 2016

PRIM’S ALGORITHM

AIM:
         To implement a C++ program for Prim’s Algorithm to find MST of an undirected graph.
ALGORITHM:

Step 1: Include the header files
Step 2: Get the number of vertices n, vertices and edges weight.
Step 3: Consider any vertex in graph process the vertex and add the vertex to the tree.
Step 4: Find the smallest edge from the graph connecting the edge of the vertex in the tree such that it  
             does not from a cycle.

Step 5: Add that vertex to the tree.
Step 6: Repeat from step 4, until the tree contains all the n vertices.

PROGRAM:

#include<iostream.h>
#include<conio.h>
using namespace std;
struct node
{
   int fr,to,cost;
}p[6];
int c = 0,temp1 = 0,temp = 0;
void prims(int *a,int b[][7],int i,int j)
{
   a[i] = 1;
   while (c < 6)
   {
       int min = 999;
       for (int i = 0; i < 7; i++)
       {
           if (a[i] == 1)
           {
               for (int j = 0; j < 7; )
               {
                   if (b[i][j] >= min || b[i][j] == 0)
                   {
                       j++;
                   }
                   else if (b[i][j] < min)
                   {
                       min = b[i][j];
                       temp = i;
                       temp1 = j;
                   }
               }
           }
       }
       a[temp1] = 1;
       p[c].fr = temp;
       p[c].to = temp1;
       p[c].cost = min;
       c++;       
       b[temp][temp1] = b[temp1][temp]=1000;
   }
   for (int k = 0; k < 6; k++)
   {
       cout<<"source node:"<<p[k].fr<<endl;
       cout<<"destination node:"<<p[k].to<<endl;
cout<<"weight of node"<<p[k].cost<<endl;
   }
}
int main()
{
   int a[7];
   for (int i = 0; i < 7; i++)
   {
       a[i] = 0;
   }
   int b[7][7];
   for (int i = 0; i < 7; i++)
   {
       cout<<"enter values for "<<(i+1)<<" row"<<endl;
       for (int j = 0; j < 7; j++)
       {
           cin>>b[i][j];
       }
   }
   prims(a,b,0,0);
   getch();
}

Sunday, February 21, 2016

BINARY SEARCH TREE AND TREE TRAVERSAL

AIM:
         To implement a C++ program to illustrate binary search tree and tree traversal techniques

ALGORITHM:

Step 1: Include the header files
Step 2: Declare a structure with two pointer fields; for left child information and right child information, one data field to store the balance factor of each node and another data field to store the node data.
Step 3: Get the elements one by one and insert it using a insert () function.
Insert () function:
  1. Place the first element as root.
  2. Perform the following steps for the next subsequent insertions.
  1. If the element is less than one root and its left sub tree is NULL then place it as the left child of the root.
  2. Else loop the insertion function taking the first left sub tree element as the root.
  3. If the element is greater than the root and its right sub tree is NULL then place element as the right child of the root.
  4. Else loop the insertion function taking the first right sub tree element as the root.
Step 4: For searching any element get the element to search and perform the following steps:
  1. Compare the element with the root node data if it is same then display element is found and its parent is present.
  2. If the element is less than the root loop the search function taking the first left sub tree element as root.
  3. If the element is greater than the root loop the search function taking the first right sub tree element as root.
  4. If the element is not present in the binary search tree then display element is not found.
Step 5: For deleting any element get the element to be deleted and perform the following steps.
  1. If the element is leaf node then delete the node.
  2. Else if the element has one child deletes it and links its parent node directly with its child node.
  3. Else if the element has two children then replace with the smallest element of the right sub tree.
Step 6: Display the element of the binary search tree.
Step 7: To traverse a non-empty binary search tree in pre-order, perform the following operations recursively at each node, starting with the root node:
  1. Visit the root.
  2. Traverse the left sub-tree.
  3. Traverse the right sub-tree.
Step 8: To traverse a non-empty binary search tree in in-order, perform the following operations recursively at each node, starting with the root node:
  1. Traverse the left sub-tree.
  2. Visit the root.
  3. Traverse the right sub-tree.

Step 9: To traverse a non-empty binary search tree in post-order, perform the following operations recursively at each node, starting with the root node:
  1. Traverse the left sub-tree.
  2. Traverse the right sub-tree.
  3. Visit the root.
PROGRAM:

# include <iostream.h>
# include <cstdlib>
using namespace std;

struct node
{
   int info;
   struct node *left;
   struct node *right;
}*root;
class BST
{
   public:
       void find(int, node **, node **);    
       void insert(int);
       void del(int);
       void case_a(node *,node *);
       void case_b(node *,node *);
       void case_c(node *,node *);
       void preorder(node *);
       void inorder(node *);
       void postorder(node *);
       void display(node *, int);
       BST()
       {
           root = NULL;
       }
};
int main()
{
   int choice, num;
   BST bst;
   node *temp;
   while (1)
   {
       cout<<"-----------------"<<endl;
       cout<<"Operations on BST"<<endl;
       cout<<"-----------------"<<endl;
       cout<<"1.Insert Element "<<endl;
       cout<<"2.Delete Element "<<endl;
       cout<<"3.Inorder Traversal"<<endl;
       cout<<"4.Preorder Traversal"<<endl;
       cout<<"5.Postorder Traversal"<<endl;
       cout<<"6.Display"<<endl;
       cout<<"7.Quit"<<endl;
       cout<<"Enter your choice : ";
       cin>>choice;
       switch(choice)
       {
       case 1:
           temp = new node;
           cout<<"Enter the number to be inserted : ";
   cin>>temp->info;
bst.insert(root, temp);
       case 2:
           if (root == NULL)
           {
               cout<<"Tree is empty, nothing to delete"<<endl;
               continue;
           }
           cout<<"Enter the number to be deleted : ";
           cin>>num;
           bst.del(num);
           break;
       case 3:
           cout<<"Inorder Traversal of BST:"<<endl;
           bst.inorder(root);
           cout<<endl;
           break;
case 4:
           cout<<"Preorder Traversal of BST:"<<endl;
           bst.preorder(root);
           cout<<endl;
           break;
       case 5:
           cout<<"Postorder Traversal of BST:"<<endl;
           bst.postorder(root);
           cout<<endl;
           break;
       case 6:
           cout<<"Display BST:"<<endl;
           bst.display(root,1);
           cout<<endl;
           break;
       case 7:
           exit(1);
       default:
           cout<<"Wrong choice"<<endl;
       }
   }
}
void BST::find(int item, node **par, node **loc)
{
   node *ptr, *ptrsave;
   if (root == NULL)
   {
       *loc = NULL;
       *par = NULL;
       return;
   }
   if (item == root->info)
{
       *loc = root;
       *par = NULL;
       return;
   }
   if (item < root->info)
       ptr = root->left;
   else
       ptr = root->right;
   ptrsave = root;
   while (ptr != NULL)
   {
       if (item == ptr->info)
       {
           *loc = ptr;
           *par = ptrsave;
           return;
       }
       ptrsave = ptr;
       if (item < ptr->info)
           ptr = ptr->left;
else
   ptr = ptr->right;
   }
   *loc = NULL;
   *par = ptrsave;
}
void BST::insert(node *tree, node *newnode)
{
   if (root == NULL)
   {
       root = new node;
       root->info = newnode->info;
       root->left = NULL;
       root->right = NULL;
       cout<<"Root Node is Added"<<endl;
       return;
   }
   if (tree->info == newnode->info)
   {
       cout<<"Element already in the tree"<<endl;
       return;
   }
   if (tree->info > newnode->info)
   {
       if (tree->left != NULL)
       {
           insert(tree->left, newnode);
}
else
{
           tree->left = newnode;
           (tree->left)->left = NULL;
           (tree->left)->right = NULL;
           cout<<"Node Added To Left"<<endl;
           return;
       }
   }
   else
   {
       if (tree->right != NULL)
       {
           insert(tree->right, newnode);
       }
       else
       {
           tree->right = newnode;
           (tree->right)->left = NULL;
           (tree->right)->right = NULL;
           cout<<"Node Added To Right"<<endl;
           return;
       }
   }
}
void BST::del(int item)
{
   node *parent, *location;
   if (root == NULL)
   {
       cout<<"Tree empty"<<endl;
       return;
   }
   find(item, &parent, &location);
   if (location == NULL)
   {
       cout<<"Item not present in tree"<<endl;
       return;
   }
   if (location->left == NULL && location->right == NULL)
       case_a(parent, location);
   if (location->left != NULL && location->right == NULL)
       case_b(parent, location);
   if (location->left == NULL && location->right != NULL)
       case_b(parent, location);
   if (location->left != NULL && location->right != NULL)
       case_c(parent, location);
else
{
           tree->left = newnode;
           (tree->left)->left = NULL;
           (tree->left)->right = NULL;
           cout<<"Node Added To Left"<<endl;
           return;
       }
   }
   else
   {
       if (tree->right != NULL)
       {
           insert(tree->right, newnode);
       }
       else
       {
           tree->right = newnode;
           (tree->right)->left = NULL;
           (tree->right)->right = NULL;
           cout<<"Node Added To Right"<<endl;
           return;
       }
   }
}
void BST::del(int item)
{
   node *parent, *location;
   if (root == NULL)
   {
       cout<<"Tree empty"<<endl;
       return;
   }
   find(item, &parent, &location);
   if (location == NULL)
   {
       cout<<"Item not present in tree"<<endl;
       return;
   }
   if (location->left == NULL && location->right == NULL)
       case_a(parent, location);
   if (location->left != NULL && location->right == NULL)
       case_b(parent, location);
   if (location->left == NULL && location->right != NULL)
       case_b(parent, location);
   if (location->left != NULL && location->right != NULL)
       case_c(parent, location);
   free(location);
}
void BST::case_a(node *par, node *loc )
{
   if (par == NULL)
   {
       root = NULL;
   }
   else
   {
       if (loc == par->left)
           par->left = NULL;
       else
           par->right = NULL;
   }
}
void BST::case_b(node *par, node *loc)
{
   node *child;
   if (loc->left != NULL)
       child = loc->left;
   else
       child = loc->right;
   if (par == NULL)
   {
       root = child;
   }
   else
   {
       if (loc == par->left)
           par->left = child;
       else
           par->right = child;
   }
}
void BST::case_c(node *par, node *loc)
{
   node *ptr, *ptrsave, *suc, *parsuc;
   ptrsave = loc;
   ptr = loc->right;
   while (ptr->left != NULL)
   {
       ptrsave = ptr;
       ptr = ptr->left;
   }
   suc = ptr;
   parsuc = ptrsave;
   if (suc->left == NULL && suc->right == NULL)
case_a(parsuc, suc);
   else
       case_b(parsuc, suc);
   if (par == NULL)
   {
       root = suc;
   }
   else
   {
       if (loc == par->left)
           par->left = suc;
       else
           par->right = suc;
   }
   suc->left = loc->left;
   suc->right = loc->right;
}
void BST::preorder(node *ptr)
{
   if (root == NULL)
   {
       cout<<"Tree is empty"<<endl;
       return;
   }
   if (ptr != NULL)
   {
       cout<<ptr->info<<"  ";
       preorder(ptr->left);
       preorder(ptr->right);
   }
}
void BST::inorder(node *ptr)
{
   if (root == NULL)
   {
       cout<<"Tree is empty"<<endl;
       return;
   }
   if (ptr != NULL)
   {
       inorder(ptr->left);
       cout<<ptr->info<<"  ";
       inorder(ptr->right);
   }
}
void BST::postorder(node *ptr)
{
   if (root == NULL)
{
       cout<<"Tree is empty"<<endl;
       return;
   }
   if (ptr != NULL)
   {
       postorder(ptr->left);
       postorder(ptr->right);
       cout<<ptr->info<<"  ";
   }
}
void BST::display(node *ptr, int level)
{
   int i;
   if (ptr != NULL)
   {
       display(ptr->right, level+1);
       cout<<endl;
       if (ptr == root)
           cout<<"Root->:  ";
       else
       {
           for (i = 0;i < level;i++)
               cout<<"       ";
}
       cout<<ptr->info;
       display(ptr->left, level+1);
   }
}

SAMPLE OUTPUT:

-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 1
Enter the number to be inserted : 8
Root Node is Added
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 6
Display BST:
Root->:  8
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 1
Enter the number to be inserted : 9
Node Added To Right
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 6
Display BST:
             9
Root->:  8
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 1
Enter the number to be inserted : 5
Node Added To Left
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 6
Display BST:
             9
Root->:  8
             5
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 1
Enter the number to be inserted : 11
Node Added To Right
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 6
Display BST:
                    11
Root->:  8
             5
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 1
Enter the number to be inserted : 3
Node Added To Left
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 1
Enter the number to be inserted : 7
Node Added To Right
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 6
Display BST:
                    11
             9
Root->:  8
                    7
             5
                    3
-----------------
             9
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 1
Enter the number to be inserted : 10
Node Added To Left
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 6
Display BST:
                    11
                           10
             9
Root->:  8
                    7
             5
                    3
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 2
Enter the number to be deleted : 10
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 6
Display BST:
                    11
             9
Root->:  8
                    7
             5
                    3
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 3
Inorder Traversal of BST:
3  5  7  8  9  11  
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 4
Preorder Traversal of BST:
8  5  3  7  9  11  
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 5
Postorder Traversal of BST:
3  7  5  11  9  8  
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 2
Enter the number to be deleted : 8
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 6
Display BST:
             11
Root->:  9
                    7
             5
                    3
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 1
Enter the number to be inserted : 10
Node Added To Left
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 6
Display BST:
             11
                    10
Root->:  9
                    7
             5
                    3
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 1
Enter the number to be inserted : 15
Node Added To Right
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 6
Display BST:
                    15
             11
Root->:  9
                    7
             5
                    3
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 4
Preorder Traversal of BST:
9  5  3  7  11  10  15  
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 5
Postorder Traversal of BST:
3  7  5  10  15  11  9  
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 6
Display BST:
                    15
             11
                    10
Root->:  9
                    7
             5
                    3
-----------------
Operations on BST
-----------------
1.Insert Element
2.Delete Element
3.Inorder Traversal
4.Preorder Traversal
5.Postorder Traversal
6.Display
7.Quit
Enter your choice : 7

RESULT:

                Thus a C++ program to illustrate binary search tree and tree traversal techniques is implemented successfully.