Data Structures Using C++ Lab - Record - II A - Dec 2020
Data Structures Using C++ Lab - Record - II A - Dec 2020
NAME :………………………………….
1
ALPHA ARTS AND SCIENCE COLLEGE
(AFFILIATED TO THE UNIVERSITY OF MADRAS)
PORUR, CHENNAI-116
Name............................................................................................................................
………………………………………………………………………………………
Submitted for the Data Structures using C++ practical Examination of the
Examiners
Date………………. Date…………………….
2
INDEX
3
Ex.No:1
ARRAY OPERATIONS
Date :
Aim
To create a C++ program to perform inserting and deleting operations using one Dimensional
Array
Algorithm
Step 1: Create array with some fixed size inside the class
Step 2: create functions for array initialization, insertion, deletion and traverse
Step 3: To read the input values for Array.
Step 4: For insertion get the position and Data.
Step 5: Through the loop statement find out the position where to insert the element.
Step 6: Once the position is reached then insert that element in that position.
Step 7: For deletion get the position value and then using the loop statement replace the
deleting element with the element in the next location and repeat the process until the last
location
Step 8: To traverse, set the loop from the starting location of the array to the end location and
display all the elements in the array.
4
ARRAY OPERATIONS
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class Arrayop
{
int n,i,arr[10],pos,data;
public:
void get();
void view();
void insert();
void del();
};
void Arrayop :: get()
{
cout<<"Enter n:";
cin>>n;
cout<<"Enter the element of array:\n";
for(i=0;i<n;i++)
cin>>arr[i];
}
void Arrayop :: insert()
{
cout<<"Enter the position of on array:";
cin>>pos;
pos=pos-1;
cout<<"Enter the insertion element:";
cin>>data;
for(i=n-1;i>=pos;i--)
{
arr[i+1]=arr[i];
}
arr[pos]=data;
n++;
}
void Arrayop :: view()
{
cout<<"The element of array is:\n";
for(i=0;i<n;i++)
cout<<arr[i]<<"\n";
}
void Arrayop :: del()
{
cout<<"Enter the position of the element:";
cin>>pos;
pos=pos-1;
for(i=pos;i<n-1;i++)
{
arr[i]=arr[i+1];
}
5
n--;
}
void main()
{
Arrayop ob;
int ch;
clrscr();
do
{
cout<<"\t\t\tArray operations\n";
cout<<"1.Input\n2.Insertion\n3.Deletion\n4.View\n5.Exit\n";
cout<<"Enter the choice:";
cin>>ch;
switch(ch)
{
case 1:ob.get();break;
case 2:ob.insert();break;
case 3:ob.del();break;
case 4:ob.view();break;
case 5:exit(0);
}
}while(ch<=5);
getch();
}
6
Output
Array operations
1.Input
2.Insertion
3.Deletion
4.View
5.Exit
Enter the choice:1
Enter n:4
Enter the element of array:
10 20 30 40
Array operations
1.Input
2.Insertion
3.Deletion
4.View
5.Exit
Enter the choice:2
Enter the position of on array:2
Enter the insertion element:15
Array operations
1.Input
2.Insertion
3.Deletion
4.View
5.Exit
Enter the choice:4
The element of array is:
10
15
20
30
40
Array operations
1.Input
2.Insertion
3.Deletion
4.View
5.Exit
Enter the choice:5
7
Result
8
Ex.No:2
STACK USING ARRAY
Date :
Aim
To create a C++ program to implement stack operations using one dimensional array
Algorithm
9
STACK USING ARRAY
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class stack
{
int s[5],top;
public:
stack()
{
top=-1;
}
void push();
void pop();
void view();
};
void stack::push()
{
if(top==5)
cout<<"The stack is full\n";
else
{
cout<<"Enter the element:";
cin>>s[++top];
}
}
void stack ::pop()
{
if(top==-1)
cout<<"Stack is empty\n";
else
cout<<"Deletion Element is:"<<s[top--]<<"\n";
}
void stack :: view()
{
if(top==-1)
cout<<"Stack is empty\n";
else
{
cout<<"Stack elements are:\n";
for(int i=top;i>=0;i--)
{
cout<<s[i]<<"\n";
}
}
}
void main()
{
stack ob;
int ch;
10
clrscr();
cout<<"\t\t\tStack Array Operations \n";
cout<<"1.Push 2.Pop 3.View 4.Exit\n";
do
{
cout<<"Enter the choice:";
cin>>ch;
switch(ch)
{
case 1:ob.push();break;
case 2:ob.pop();break;
case 3:ob.view();break;
case 4:exit(0);
}
}while(ch<=4);
getch();
}
11
Output
12
Result
13
Ex.No:3
QUEUE USING ARRAY
Date :
Aim
To create a C++ program to implement Queue Operations using one dimensional Array
Algorithm
14
QUEUE USING ARRAY
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class queue
{
private:
int q[5],rear,front;
public:
queue()
{
rear=front= -1;
}
void enq();
void deq();
void view();
};
void queue :: enq()
{
if(front ==0 && rear==4)
cout<<"Queue is Full\n";
else
{
if(front ==-1)
{
front=0;
}
cout<<"Enter the Data:";
cin>>q[++rear];
}
}
void queue :: deq()
{
if(front==-1)
cout<<"Queue if Empty\n";
else
{
if(rear==front)
{
rear=front=-1;
}
else
{
int x=q[front];
cout<<"dequeue element="<<x<<endl;
front++;
}
}
}
void queue :: view()
15
{
if(front==-1)
cout<<"Queue if Empty\n";
else
{
for(int i=front;i<=rear;i++)
cout<<q[i]<<"\n";
}
}
void main()
{
queue q;
clrscr();
int ch;
cout<<"\t\t\tQueue Using Array\n";
cout<<"1.Insertion 2.Deletion 3.View 4.Exit\n";
do
{
cout<<"Enter the choice:";
cin>>ch;
switch(ch)
{
case 1:q.enq();break;
case 2:q.deq();break;
case 3:q.view();break;
case 4:exit(0);
}
}while(ch<=4);
getch();
}
16
Output
17
Result
18
Ex.No:4
STACK USING POINTER
Date :
Aim
Algorithm
Step 1: Create node using structure with data part and address part
Step 2: Read the stack operation
19
STACK USING POINTER
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
int no;
node *next;
}*top,*temp;
class stack
{
public:
stack() //constructor
{
top=NULL;
}
void push();
void pop();
void view();
};
void stack :: push()
{
temp=new node; //new-dynamic memory allocation operator
cout<<"Enter the Number:";
cin>>temp->no;
temp->next=NULL;//Null value is stored in first time
if(top==NULL)
{
top=temp;//Assign new node as a top
}
else
{
temp->next=top;
top=temp;
}
}
void stack :: pop()
{
if(top==NULL)
cout<<"Stack is Empty\n";
else
{
temp=top;
cout<<"Deleted Element is:"<<temp->no<<"\n";
top=temp->next;
delete temp;
}
}
void stack :: view()
{
20
if(top==NULL)
cout<<"stack is Empty\n";
else
{
for(temp=top;temp!=NULL;temp=temp->next)
{
cout<<temp->no<<"\n";
}
}
}
void main()
{
int ch;
clrscr();
stack m;
cout<<"\t\t\tStack Operations\n";
cout<<"1.Push 2.Pop 3.View 4.Exit\n";
do
{
cout<<"Enter the choice:";
cin>>ch;
switch(ch)
{
case 1:m.push();break;
case 2:m.pop();break;
case 3:m.view();break;
case 4:exit(0);
}
}while(ch<=4);
getch();
}
21
Output
Stack Operations
1.Push 2.Pop 3.View 4.Exit
Enter the choice:1
Enter the Number:10
Enter the choice:1
Enter the Number:20
Enter the choice:1
Enter the Number:30
Enter the choice:3
30
20
10
Enter the choice:2
Deleted Element is:30
Enter the choice:4
22
Result
23
Ex.No:5
QUEUE USING POINTER
Date :
Aim
Algorithm
Step 1: Create node using structure with data part and address part
24
QUEUE USING POINTER
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
int no;
node *next;
}*front,*rear,*temp;
class queue
{
public:
queue()
{
front=NULL;
rear=NULL;
}
void insert();
void del();
void display();
};
void queue :: insert()
{
temp=new node;
cout<<"Enter the Number:";
cin>>temp->no;
temp->next=NULL;
if(front==NULL)
front=temp;
else
{
rear->next=temp;
}
rear=temp;
}
void queue::del()
{
if(front==NULL)
cout<<"Queue is empty\n";
else
{
temp=front;
front=temp->next;
cout<<"Delete Element IS:"<<temp->no<<"\n";
delete temp;
}
}
void queue::display()
{
if(front==NULL)
25
cout<<"Queue is empty\n";
else
{
for(temp=front;temp!=NULL;temp=temp->next)
cout<<temp->no<<"\n";
}
}
void main()
{
queue q;
clrscr();
int ch;
cout<<"\t\t\tQueue Using Pointer\n";
cout<<"1.Insertion 2.Deletion 3.View 4.Exit\n";
do
{
cout<<"Enter the choice:";
cin>>ch;
switch(ch)
{
case 1: q.insert(); break;
case 2: q.del(); break;
case 3: q.display(); break;
case 4: exit(0);
}
}while(ch<=4);
getch();
}
26
Output
27
Result
28
Ex.No:6
ADDITION OF TWO POLNOMIALS USING ARRAY
Date :
Aim
Algorithm
Step 1: Create polynomial using structure with coefficient part and exponent part
Step 2: Before using read(), enter the number of terms in each polynomial
Step 3: If the operation is read then
Enter the coefficient and exponent of two polynomials
Repeat the process until it reaches the maximum number of terms (n)
Step 4: If the operation display then do the following steps.
Print the coefficient and exponent part of both polynomials
Add + between each terms if it’s not last before term
Add new line after the first polynomial
Repeat the process until it reaches the maximum number of terms (n)
Step 5: If the operation is operator+ then do the following steps
If p1.exponent > p2.exponent then
P3.coefficent = p1.coefficient
P3.exponent = p1.exponent
Else if p1.exponent < p2.exponent then
P3.coefficent = p2.coefficient
P3.exponent = p2.exponent
Else if p1.exponent = p2.exponent then
P3.coeffcient = p1.coefficient + p2.coefficient
P3. Exponent = either p1.exponent or p2.exponent
Repeat the above process until last term is reached in both polynomials and return P3
29
ADDITION OF TWO POLYNOMIALS USING ARRAY
#include<iostream.h>
#include<conio.h>
struct poly
{
int coeff;
int exp;
};
class polynomial
{
struct poly p[20];
public:
int n;
void read();
void display();
polynomial operator+(polynomial);
};
void polynomial::read()
{
int i;
for(i=0;i<n;i++)
{
cout<<"\n Enter the coefficient & exponents:";
cin>>p[i].coeff>>p[i].exp;
}
}
void polynomial::display()
{
for(int i=0;i<n;i++)
{
cout<<p[i].coeff<<" x^ "<<p[i].exp;
if(i!=n-1)
cout<<" + ";
}
cout<<"\n";
}
polynomial polynomial::operator +(polynomial p2)
{
polynomial p3;
int i=0,j=0,k=0;
while((i<n)&&(j<p2.n))
{
if(p[i].exp>p2.p[j].exp)
{
p3.p[k]=p[i];
i++;
}
else if(p[i].exp<p2.p[j].exp)
{
p3.p[k]=p2.p[j];
30
j++;
}
else
{
p3.p[k].coeff=p[i].coeff+p2.p[j].coeff;
p3.p[k].exp=p[i].exp;
i++;
j++;
}
k++;
}
while(i<n)
{
p3.p[k]=p[i];
i++;
k++;
}
while(j<p2.n)
{
p3.p[k]=p2.p[j];
j++;
k++;
}
p3.n=k;
return p3;
}
void main()
{
polynomial p1,p2,p3;
clrscr();
cout<<"\n Enter the no of terms in 1st polynomial:";
cin>>p1.n;
p1.read();
cout<<"\n Enter the no of terms in 2nd polynomial:";
cin>>p2.n;
p2.read();
cout<<"\n 1st polynomial is:\n";
p1.display();
cout<<"\n 2nd polynomial is:\n";
p2.display();
p3=p1+p2;
cout<<"\n Resultant polynomial is:";
p3.display();
getch();
}
31
Output
32
Result
33
Ex.No:7 CONVERSION OF INFIX EXPRESSION TO POSTFIX
Date : EXPRESSION
Aim
To Create a C++ program that converts a given Infix Expression into Postfix Expression
Algorithm
Step 1: Create a class named Postfix with Character Array Expression of fixed size.
34
INFIX TO POSTFIX CONVERSION
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
class postfix
{
char s[20];
public:
void get();
void convert();
int prior(char c);
};
void postfix :: get()
{
cout<<"\t\t\tInfix to Postfix Expression Evaluation\n";
cout<<"Enter Infix Expression:";
cin>>s;
strcat(s,")");
}
int postfix :: prior(char c)
{
int pr;
switch(c)
{
case '^':pr=3;break;
case '*':
case '/':
case '%':pr=2;break;
case '+':
case '-':pr=1;break;
}
return pr;
}
void postfix :: convert()
{
char op[20],a;
int t=0,i=0;
op[++t]='(';
cout<<"Postfix:";
while(t>0)
{
a=s[i];
if(isalpha(a))
cout<<a;
else if(a=='(')
op[++t]=a;
else if(a==')')
{
35
while(op[t]!='(')
cout<<op[t--];
t--;
}
else
{
while(prior(op[t])>=prior(a)&&op[t]!='(')
cout<<op[t--];
op[++t]=a;
}
i++;
}
}
void main()
{
postfix p;
clrscr();
p.get();
p.convert();
getch();
}
36
Output
37
Result
38
Ex.No:8
EVALUATION OF POSTFIX EXPRESSION
Date :
Aim
Algorithm
39
EVALUATION OF POSTFIX EXPRESSION
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
class postfix
{
char s[30];
int a[30],top,op1,op2;
public:
postfix()
{
top=0;
}
void get();
int cal(int,int,char);
};
void postfix :: get()
{
cout<<"\t\t\t\t\tPostfix Evaluation\n\n";
cout<<"Enter the postfix Expression:";
cin>>s;
for(int i=0;i<strlen(s);i++)
{
if(isalpha(s[i]))
{
cout<<"Enter the Value of "<<s[i]<<":";
cin>>a[++top];
}
else
{
op1=a[top--];
op2=a[top];
a[top]=cal(op2,op1,s[i]);
}
}
cout<<"The Output is:"<<a[1];
}
int postfix :: cal(int a,int b,char c)
{
switch(c)
{
case '+':return a+b;
case '-':return a-b;
case '*':return a*b;
case '/':return a/b;
case '%':return a%b;
case '^':return (pow(a,b));
40
}
}
void main()
{
postfix p;
clrscr();
p.get();
getch();
}
41
Output
Postfix Evaluation
42
Result
43
Ex.No:9
SINGLE LINKED LIST
Date :
Aim
To perform creation, insertion, deletion and view in Single Linked List using C++
Algorithm
Step 1: Create node using structure with data part and address part
Else
44
Step 5: If the operation delete then do the following steps.
45
SINGLE LINKED LIST
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class sll
{
struct node
{
int no;
node *next;
}*head,*tail,*temp,*temp1;
public:
sll()
{
head=NULL;
}
void create();
void insert();
void del();
void view();
~sll(){ }
};
void sll :: create()
{
temp= new node;
cout<<"Enter the Number:";
cin>>temp->no;
temp->next=NULL;
if(head==NULL)
{
head=temp;
}
else
{
tail->next=temp;
}
tail=temp;
}
void sll :: view()
{
for(temp=head;temp!=NULL;temp=temp->next)
cout<<temp->no<<"\t";
cout<<"\n";
}
void sll :: insert()
{
temp=head;
int pos,i=1;
cout<<"Enter the Position:";
cin>>pos;
46
temp1=new node;
cout<<"Enter the data:";
cin>>temp1->no;
if(pos==1)
{
temp1->next=head;
head=temp1;
}
else
{
while(i<pos-1)
{
temp=temp->next;
i++;
}
temp1->next=temp->next;
temp->next=temp1;
}
}
void sll :: del()
{
temp=head;
int pos,i=1;
cout<<"Enter the position:";
cin>>pos;
if(pos==1)
head=head->next;
else
{
while(i<pos)
{
temp1=temp;
temp=temp->next;
i++;
}
temp1->next=temp->next;
delete(temp);
}
}
void main()
{
sll m;
clrscr();
int ch1;
cout<<"\t\t\tLinked List Program\n";
cout<<"1.Create 2.Insert 3.Delete 4.view 5.Exit\n";
do{
cout<<"Enter the choice:";
cin>>ch1;
switch(ch1)
{
case 1:m.create();break;
47
case 2:m.insert();break;
case 3:m.del();break;
case 4:m.view();break;
case 5:exit(0);
}
}while(ch1<6);
getch();
}
48
Output
49
Result
50
Ex.No:10
DOUBLE LINKED LIST
Date :
Aim
To perform creation, insertion, deletion and view in Double Linked List using C++
Algorithm
Step 1: Create node using structure with data part, next address part and previous address part
52
DOUBLE LINKED LIST
#include<stdlib.h>
#include<iostream.h>
#include<conio.h>
struct node
{
int no;
node *next,*prev;
}*temp,*temp1,*head,*tail;
class dll
{
public:
dll()
{
head=tail=NULL;
}
void create();
void del();
void fview();
void bview();
void insert();
};
void dll::create()
{
char ch;
x:temp=new node;
cout<<"enter data:";
cin>>temp->no;
temp->next=temp->prev=NULL;
if(head==NULL)
head=temp;
else
{
tail->next=temp;
temp->prev=tail;
}
tail=temp;
}
void dll::fview()
{
for(temp=head;temp!=NULL;temp=temp->next)
{
cout<<temp->no<<"\t";
}
}
void dll::bview()
{
for(temp=tail;temp!=NULL;temp=temp->prev)
{
cout<<temp->no<<"\t";
53
}
}
void dll::insert()
{
temp=head;
int i=1,pos;
temp1=new node;
cout<<"\nenter data:";
cin>>temp1->no;
temp1->next=temp->prev=NULL;
cout<<"\nenter the pos:";
cin>>pos;
if(pos==1)
{
temp1->next=head;
head->prev=temp1;
head=temp1;
}
else
{
while(i<pos-1)
{
temp=temp->next;
i++;
}
temp1->next=temp->next;
temp->next->prev=temp1;
temp->next=temp1;
temp1->prev=temp;
}
}
void dll::del()
{
int i=1,pos;
temp=head;
cout<<"enter pos:";
cin>>pos;
if(pos==1)
{
head=head->next;
head->prev=NULL;
}
else
{
while(i<pos)
{
temp1=temp;
temp=temp->next;
i++;
}
temp1->next=temp->next;
temp->next->prev=temp->prev;
54
delete(temp);
}
}
void main()
{
int c;
clrscr();
dll s;
cout<<"double link list operations\n";
cout<<"1.create\n2.fview\n3.insert\n4.del\n5.bview\n6.exit\n";
do
{
cout<<"\nenter your choice:";
cin>>c;
switch(c)
{
case 1:s.create();break;
case 2:s.fview();break;
case 3:s.insert();break;
case 4:s.del();break;
case 5:s.bview();break;
case 6:exit(0);
}
}while(c<=6);
getch();
}
55
Output
enter data:5
56
Result
57
Ex.No:11
BINARY TREE TRAVERSALS
Date :
Aim
To perform Binary Tree Traversals (pre-order, in-order and post-order) using C++ program
Algorithm
Step 1: Create node using structure with data part, left child part and right child part
Set p->left = p->right = NULL (initially left and right of the root are NULL)
Enter value (0/1) for creating left child :
If 1 means it creates a node to the left of the root
Enter the value for the left child node
If 0 means it won’t create a node to the left of the root
Enter value (0/1) for creating right child :
If 1 means it creates a node to the right of the root
Enter the value for the right child node
If 0 means it won’t create a node to the right of the root
If p! = NULL then
Print p->no
Call preorder (p->left)
Call preorder (p->left)
If p! = NULL then
Call preorder (p->left)
58
print p->no
Call preorder (p->right)
If p! = NULL then
Call preorder (p->left)
Call preorder (p->right)
print p->no
print p->no
59
TREE TRAVERSALS
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
int no;
node *left,*right;
}*root;
class tree
{
public:
tree()
{
root=NULL;
}
void create(node *);
void inorder(node *);
void postorder(node *);
void preorder(node *);
~tree(){}
};
void tree :: create(node *p)
{
int t;
p->left=p->right=NULL;
cout<<"Enter 1 to add one to left of"<<p->no<<":";
cin>>t;
if(t==1)
{
p->left=new node;
cout<<"Enter value:";
cin>>p->left->no;
create(p->left);
}
cout<<"Enter 1 to add one node to right of"<<p->no<<":";
cin>>t;
if(t==1)
{
p->right=new node;
cout<<"Enter the value:";
cin>>p->right->no;
create(p->right);
}
}
void tree :: inorder(node *p)
{
if(p!=NULL)
{
inorder(p->left);
60
cout<<p->no<<" ";
inorder(p->right);
}
}
void tree :: preorder(node *p)
{
if(p!=NULL)
{
cout<<p->no<<" ";
preorder(p->left);
preorder(p->right);
}
}
void tree :: postorder(node *p)
{
if(p!=NULL)
{
postorder(p->left);
postorder(p->right);
cout<<p->no<<" ";
}
}
void main()
{
tree t;
int ch;
clrscr();
root=new node;
cout<<"\t\t\tTREE TRAVERSALS";
cout<<"\n\tEnter the root value:";
cin>>root->no;
t.create(root);
cout<<"\n1.INORDER 2.PREORDER 3.POSTORDER 4.EXIT";
do{
cout<<"\nEnter the Choice:";
cin>>ch;
switch(ch)
{
case 1:t.inorder(root);break;
case 2:t.preorder(root);break;
case 3:t.postorder(root);break;
case 4:exit(0);
}
}while(ch<=4);
getch();
}
61
Output
62
Result
63
Ex.No:12 GRAPH TRAVERSALS: BREADTH FIRST SEARCH AND
Date : DEPTH FIRST SEARCH
Aim
Algorithm
Step 1: create a class graph with variables vertex[10], int visited[10], static int adj[10][10]
Step 2: create functions like create(), breadth() and depth() inside the class
Step 5: If the case is one perform the DFS to search the element in column wise.
Step 6: If the case is two perform the BFS to search the element in depth (row) wise.
64
GRAPH TRAVERSAL – BFS & DFS
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class graph
{
int vertex[10];
int visited[10];
static int adj[10][10];
public:
void create(int);
void depth(int,int);
void breath(int);
};
void graph :: create(int v)
{
int i,j,k,m,n;
for(i=0;i<v;i++)
{
cout<<"Enter the node value";
cin>>vertex[i];
visited[i]=0;
}
for(i=0;i<v;i++)
{
cout<<"Enter the no.adjacent vertices fo"<<vertex[i]<<":";
cin>>n;
for(j=0;j<n;j++)
{
cout<<"Enter the adjacent vertex....";
cin>>m;
for(k=0;k<v;k++)
{
if(vertex[k]==m)
adj[i][k]=1;
}
}
adj[0][0]=1;
}
}
void graph :: depth(int a,int v)
{
int j;
for(j=0;j<v;j++)
if(adj[a][j]==1)
if(visited[j]==0)
{
visited[j]=1;
cout<<vertex[j]<<"--->";
depth(j,v);
65
}
}
void graph :: breath(int v)
{
int i,j;
for(i=0;i<v;i++)
visited[i]=0;
for(i=0;i<v;i++)
for(j=0;j<v;j++)
if(adj[i][j]==1)
if(visited[j]==0)
{
visited[j]=1;
cout<<vertex[j]<<"--->";
}
cout<<"\n";
}
int graph :: adj[10][10];
void main()
{
int n,ch;
graph g;
clrscr();
cout<<"Enter the no of vertices in the graph:";
cin>>n;
g.create(n);
do{
cout<<"\n1.DFS 2.BFS 3.EXIT";
cout<<"\nEnter your choice:";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\n\nDFS Traversals method\n";
g.depth(0,n);
cout<<"end";
cout<<"\n"<<"\n";
break;
case 2:
cout<<"\n\nBFS Traversals method\n";
g.breath(n);
cout<<"\n"<<"\n";
break;
case 3:
exit(0);
}
}while(ch<=3);
getch();
}
66
Output
67
Result
68