C++ Practical Program (1-15)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 48

1. Program to check whether the given Number is prime or not.

************************************************************************
Program:

#include<iostream.h>
#include<conio.h>
class prime
{
int a,k,i;
public:
prime (int x)
{
a=x;
}
void calculate()
{
k=1;
{
for(i=2;i<=a/2;i++)
if(a%i==0)
{
k=0;
break;
}
else
{
k=1;
}
}
}
void show()
{
if(k==1)
cout<<”\n”<<a<<”is a prime number”;
else
cout<<”\n”<<a<<”is not a prime number”;
}
};
int main()
{
int a;
cout<<”enter the number:”;
cin>>a;
prime obj(a);
obj.calculate();
obj.show();
getch();
return 0;
}
Output (Prime number)
*****************************
Enter the number: 11
11 is a prime number
Enter the number: 10
10 is not a prime number
2. Program to implement copy constructor.
*************************************
Program:
#include<iostream.h>
#include<conio.h>
class Demo
{
private:
int num1, num2;
public:
Demo(int n1, int n2)
{
num1 = n1;
num2 = n2;
}
Demo(const Demo &n)
{
num1 = n.num1;
num2 = n.num2;
}
void display()
{
cout<<"num1 = "<< num1 <<endl;
cout<<"num2 = "<< num2 <<endl;
}
};
int main()
{
Demo obj1(10, 20);
Demo obj2 = obj1;
obj1.display();
obj2.display();
return 0;
}
Output (Copy constructor)
***********************
num1 = 10
num2 = 20
num1 = 10
num2 = 20
3.Program using Inline function to find factorial of a given no.
*****************************************************
Program:
#include <iostream.h>
#include <conio.h>
inline void factorial (int x)
{
int i,f=1,p=1;
for(i=1;i<=x;i++)
{
f=f*i;
}
cout<<"Factorial of "<<x<<" is "<<f<<endl;
}
int main( )
{
int i, N;
cout<<"C++ Program to print factorial of first N natural
numbers"<<endl<<endl;
cout<<"Enter total number of natural numbers:"<<endl;
cin>>N;
for(i=1;i<=N;i++)
{
factorial(i);
}
getch();
return 0;
}
Output(Factorial using Inline function)
**********************************
C++ Program to print factorial of first N natural numbers
Enter total number of natural numbers:
6
Factorial of 1 is 1
Factorial of 2 is 2
Factorial of 3 is 6
Factorial of 4 is 24
Factorial of 5 is 120
Factorial of 6 is 720
4.Program to Implement Operator Overloading.
*****************************************
Program:
#include<iostream.h>
#include<conio.h>
class temp
{
private:
int data;
public:
void getvalue()
{
cin>>data;
}
temp operator+(temp ob)
{
temp t;
t.data=data + ob.data;
return t;
}
temp operator- (temp ob)
{
temp t;
t.data = data - ob.data;
return t;
}
int display()
{
return data;
}
};
int main()
{
temp obj1, obj2, sum, sub;
cout<<"Enter an integer value for obj1: ";
obj1.getvalue();
cout<<"Enter an integer value for obj2: ";
obj2.getvalue();
sum= obj1+obj2;
sub=obj1-obj2;
cout<<"Addition result is = "<<sum.display()<<endl;
cout<<"Subtraction result is = "<<sub.display()<<endl;
getch();
}
Output (Operator Overloading)
***************************
Enter an integer value for obj1:20
Enter an integer value for obj2:10
Addition result is=30
Subtraction result is =10
5 . Program to implement Multiple Inheritance.
*****************************************
Program:
#include <iostream.h>
#include<conio.h>
class A
{
public:
int x;
void getx()
{
cout << "enter value of x: "; cin >> x;
}
};
class B
{
public:
int y;
void gety()
{
cout << "enter value of y: "; cin >> y;
}
};
class C : public A, public B
{
public:
void sum()
{
cout << "Sum = " << x + y;
}
};
int main()
{
C obj1;
obj1.getx();
obj1.gety();
obj1.sum();
return 0;
}
Output(Multiple Inheritance)
**************************
enter value of x: 5
enter value of y: 4
Sum = 9
6 . Program to implement Push, Pop Operations of Stack using Arrays.
*************************************************************
Program:
#include <iostream>
#include<conio.h>
using namespace std;
int stack[100], n=100, top=-1;
void push(int val) {
if(top>=n-1)
cout<<"Stack Overflow"<<endl;
else {
top++;
stack[top]=val;
}
}
void pop() {
if(top<=-1)
cout<<"Stack Underflow"<<endl;
else {
cout<<"The popped element is "<< stack[top] <<endl;
top--;
}
}
void display() {
if(top>=0) {
cout<<"Stack elements are:";
for(int i=top; i>=0; i--)
cout<<stack[i]<<" ";
cout<<endl;
} else
cout<<"Stack is empty";
}
int main()
{
int ch, val;
cout<<"1) Push in stack"<<endl;
cout<<"2) Pop from stack"<<endl;
cout<<"3) Display stack"<<endl;
cout<<"4) Exit"<<endl;
do
{
cout<<"Enter choice: "<<endl;
cin>>ch;
switch(ch) {
case 1: {
cout<<"Enter value to be pushed:"<<endl;
cin>>val;
push(val);
break;
}
case 2:
{
pop();
break;
}
case 3:
{
display();
break;
}
case 4:
{
cout<<"Exit"<<endl;
break;
}
default:
{
cout<<"Invalid Choice"<<endl;
}
}
} while(ch!=4);
return 0;
}
Output(Push,Pop Operation using Array)
************************************
1) Push in stack
2) Pop from stack
3) Display stack
4) Exit
Enter choice: 1
Enter value to be pushed: 2
Enter choice: 1
Enter value to be pushed: 6
Enter choice: 1
Enter value to be pushed: 8
Enter choice: 1
Enter value to be pushed: 7
Enter choice: 2
The popped element is 7
Enter choice: 3
Stack elements are:8 6 2
Enter choice: 5
Invalid Choice
Enter choice: 4
Exit
7. Program to implement Push, Pop Operations of Stack using Pointers.
*************************************************************
Program:
#include<iostream.h>
#include<conio.h>
struct node
{
int data;
node *next;
};
class stack
{
node *top;
public:
stack()
{
top=NULL;
}
void push();
void pop();
void display();
};
void stack::push()
{
node *newlink;
newlink=new node;
cout<<"enter the pointer element to push"<<endl;
cin>>newlink->data;
newlink->next=top;
top=newlink;
cout<<"push operation is successful";
}
void stack::pop()
{
if(top==NULL)
cout<<"stack is empty";
else
{
node *t;
t=top;
top=top->next;
cout<<"popped the elements"<<t->data;
delete t;
cout<<"\n pop operation is successful";
}
}
void stack::display()
{
node *curt=top;
if(top==NULL)
cout<<"stack empty";
else
{
cout<<"the elements in the stack is\n";
while(curt!= NULL)
{
cout<<curt->data;
curt = curt->next;
}
}
}
void main()
{
stack s1;
int ch=0;
clrscr();
cout<<"stack operation using pointer";
cout<<"\n 1.PUSH \n 2.POP \n 3.DISPLAY \n4.EXIT\n";
while(ch!=4)
{
cout<<"enter the choice:";
cin>>ch;
switch(ch)
{
case 1:
s1.push();
break;
case 2:
s1.pop();
break;
case 3:
s1.display();
break;
case 4:
cout<<"program terminated";
break;
}
}
getch();
}
Output (Push,Pop Operation using Pointer)
**************************************
STACK OPERATION USING POINTER
1.PUSH
2.POP
3.DISPLAY
4.EXIT
Enter the choice: 1
enter the pointer element to push: 20
push operation is successful.
Enter the choice: 1
enter the pointer element to push: 30
push operation is successful

Enter the choice: 2


popped the elements: 30
pop operation is successful

Enter the choice: 3


the elements in the stack are: 20

Enter the choice: 4


Program terminated.

8.Program to implement Add, Delete Operations of Queue using Arrays.


***************************************************************
Program:
#include <iostream.h>
#include<conio.h>
int queue[100], n = 100, front = - 1, rear = - 1;
void Insert()
{
int val;
if (rear == n - 1)
cout<<"Queue Overflow"<<endl;
else
{
if (front == - 1)
front = 0;
cout<<"Insert the element in queue : "<<endl;
cin>>val;
rear++;
queue[rear] = val;
}
}
void Delete()
{
if (front == - 1 || front > rear)
{
cout<<"Queue Underflow ";
return ;
}
else
{
cout<<"Element deleted from queue is : "<< queue[front] <<endl;
front++;;
}
}
void Display()
{
if (front == - 1)
cout<<"Queue is empty"<<endl;
else
{
cout<<"Queue elements are : ";
for (int i = front; i <= rear; i++)
cout<<queue[i]<<" ";
cout<<endl;
}
}
int main()
{
int ch;
cout<<"1) Insert element to queue"<<endl;
cout<<"2) Delete element from queue"<<endl;
cout<<"3) Display all the elements of queue"<<endl;
cout<<"4) Exit"<<endl;
do
{
cout<<"Enter your choice : "<<endl;
cin>>ch;
switch (ch)
{
case 1: Insert();
break;
case 2: Delete();
break;
case 3: Display();
break;
case 4: cout<<"Exit"<<endl;
break;
default: cout<<"Invalid choice"<<endl;
}
} while(ch!=4);
return 0;
}
Output (Add, Delete Operations of Queue using Arrays)
************************************************
1) Insert element to queue
2) Delete element from queue
3) Display all the elements of queue
4) Exit
Enter your choice: 1
Insert the element in queue: 4
Enter your choice: 1
Insert the element in queue: 3
Enter your choice: 1
Insert the element in queue: 5
Enter your choice: 2
Element deleted from queue is: 4
Enter your choice: 3
Queue elements are: 3 5
Enter your choice: 7
Invalid choice
Enter your choice: 4
Exit

9 .Program to implement Add, Delete Operations of Queue using Pointers.


****************************************************************
#include <iostream.h>
#include <conio.h>
#include <malloc.h>
struct node
{
int data;
node *link;
};
struct q1
{
node *front;
node *rear;
node *link;
};

struct queue
{
q1 q;
node *t;
public:
void initialize()
{
q.front = NULL;
q.rear = NULL;
}
void addq();
void delq();
void displayq();
};
void queue:: addq()
{
t = new(node);
cout << "Enter Item To Add:";
cin >> t->data;
cout << "Item Added is:" << t->data;
t->link = NULL;
if((q.rear)== NULL)
q.front = t;
else
q.rear->link = t;
q.rear = t;
}
void queue::delq()
{
if(q.front == NULL)
{
cout << "Queue Is Empty";
q.rear = NULL;
}
else
{
t = q.front;
cout << "Item Deleted Is:" << q.front->data;
q.front=q.front->link;
free(t);
}
}

void queue::displayq()
{
if(q.front == NULL)
{
cout << " Queue Is Empty";
}
else
{
cout << "\nFRONT";

for(t=q.front;t!=NULL;t=t->link)
cout << "-->" << t->data;
cout << "<--REAR\n";
}
}

void main()
{
int choice;
queue qu;
clrscr();
qu.initialize();
cout <<"\n\t1-ADD";
cout <<"\n\t2-DELETE";
cout <<"\n\t3-DISPLAY";
cout <<"\n\t4-EXIT";
while(choice != 4)
{
cout << "\nEnter Your Choice:\t";
cin >> choice;
switch(choice)
{
case 1:
qu.addq();
break;
case 2:
qu.delq();
break;
case 3:
qu.displayq();
break;
case 4:
break;
default:
cout << "Invalid Choice";
}
}

Output (Add, Delete Operations of Queue using Pointers)


*************************************************
1-ADD
2-DELETE
3-DISPLAY
4-EXIT
Enter Your Choice: 1
Enter Item to Add: 44
Item Added is: 44
Enter Your Choice: 1
Enter Item to Add: 55
Item Added is: 55
Enter Your Choice: 3

FRONT-->44-->55<--REAR

Enter Your Choice: 2


Item Deleted Is: 44
Enter Your Choice: 3

FRONT-->55<--REAR

Enter Your Choice: 4


Exit
10. CONVERSION OF INFIX TO POSTFIX
***************************************
Program:
#include<iostream.h>
#include<stdio.h>
#include<ctype.h>
char stack[100];
int top=-1;
void push(char x)
{
stack[++top]=x;
}
char pop()
{
if(top==-1}
return -1;
else
return stack[top--];
}
int priority(char x)
{
if(x==’(‘)
return 0;
if(x == ’+’|| x == ’-‘)
return 1;
if(x == ’*’ || x == ’/’)
return 2;
return 0;
}
int main()
{
char exp[100];
char *e,x;
cout<<”enter the expression “;
cin>>exp;
cout<<”\n”;
e=exp;
while(*e!=’\0’)
{
if(isalnum(*e))
cout<<*e;
else if(*e ==’(‘)
push(*e);
else if(*e==’)’)
{
while((x=pop())!=’(‘)
cout<<x;
}
else
{
while(priority(stack[top])>=priority(*e))
cout<<pop();
push(*e);
}
e++;
}
while(top !=-1)
{
cout<<pop();
}
}
OUTPUT (INFIX TO POSTFIX EXPRESSION)
*****************************************
Enter the expression :a+b*c
abc*+
Enter the expression: (a+b)*c+(d-a)
ab+c*da-+
Enter the expression : ((4+8)(6-5))/((3-2)(2+2))
48+65-32-22+/
11. Postfix Expression Evaluation
*****************************
Program:
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<string.h>
#include<math.h>
class expr
{
private:
char str[100];
int len;
public:
expr()
{
}
~expr()
{
}
void inputexpr();
void eval();
};
void expr::inputexpr()
{
cout<<”\n\t\t program to evaluate the given postfix expression”;
cout<<”\n\t\t enter the postfix expression: ”;
cin>>str;
cout<<”\n\t\t given postfix expression= ”<<str<<endl;
len=strlen (str);
cout<<”\n\t\t length-“<<len<<endl;
}
void expr::eval()
{
int stk[50],a,b,c,L=0,top=0;
char item;
while(L<len)
{
item=str[L]
if((item>47)&&(item<58))
{
top++;
stk[top]=item-48;
}
else
{
b=stk[top];
top--;
a=stk[top];
top--;
top++;
switch(item)
{
case’+’:
c=a+b;
break;
case’-‘:
c=a-b;
break;
case’*‘:
c=a*b;
break;
case’/‘:
c=a/b;
break;
case ‘a’
pow(a,b);
break;
stk[top]=c;
}
L++;
}
cout<<”\n\t\t evaluated result=”<<int(stk[top]);
}
void main()
{
expr e;
clrcsr();
e.inputexpr();
c.eval();
getch();
}
OUTPUT: (POSTFIX EXPRESSION EVALUATION)
***********************************************
PROGRAM TO EVALUATE THE GIVEN POSTFIX EXPRESSION
Enter the postfix expression:34*6-
Given postfix expression=34*6-
Length=5
Evaluated result=6
12. Addition of Two Polynomial
*****************************
PROGRAM:
#include<iostream.h>
#include<conio.h>
int max(int m,int n)
{
return(m>n)?m:n;
}
int*add(int A[ ],int B [ ],int m,int n)
{
int size = max(m,n);
int*sum=new int [size];
for(int i=0;i<m;i++)
sum[i]=A[i];
for(i=0;i<n;i++)
sum[i] +=B[i];
return sum;
}
void printpoly(int poly[ ],int n)
{
for(int i=0;i<n;i++)
{
cout<<poly[i];
if(i !=0)
cout<<”x^”<<i;
if(i !=n-1)
cout<<”+”;
}
}
int main()
{
int A[ ]={5,8,10,6};
int B[ ]={1,2,4,8};
int m=sizeof(A)/sizeof(A[0]);
int n =sizeof(B)/sizeof(B[0]);
cout<<”First polynomial is\n”;
printpoly(A,m);
cout<<”Second polynomial is\n”;
printpoly(B,n);
int*sum=add(A,B,m,n);
int size=max(m,n);
cout<<”\n Sum of polynomial is\n;
printpoly(sum,size);
return 0;
}
OUTPUT (ADDITION OF TWO POLYNOMIAL)
********************************************
First polynomial is
5+8x^1+10x^2+6x^3

Second polynomial is

1+2x^1+4x^2+8x^3

Sum of polynomial is

6+2x^1+14x^2+14x^3
13. CREATION, INSERTION AND DELETION IN DOUBLY LINKED
****************************************************************
LIST
*****
PROGRAM:
#include<iostream.h>
#include<conio.h>
struct node
{
node*left;
node*right;
int data;
}*p;
node *head,*temp,*perm,*temp1,*ins;
char ans;
int an1,da1,cho,flag;
class dll
{
public:
void display(node *head);
void create();
void insert();
void dele();
};
void dll::create()
{
head=new node;
head->left=NULL;
cout<<”\n\t\t\t enter the data:”;
cin>>head->data;
head->right=NULL;
}
void dll::insert()
{
flag=0;
cout<<”\n\t\t\t before which element to insert(press 0 to add at end):”;
cin>>an1;
cout<<an1;
ins=new node;
cout<<”\n\t\t\t insert the data:”;
cin>>ins->data;
cout<<ins->data;
ins->right=NULL;
if(head->data==an1)
{
ins->right=head;
head->left=ins;
head=ins;
}
else
if(an1==0)
{
temp=head;
while(temp!=NULL)
{
perm=temp;
temp=temp->right;
}
perm->right=ins;
ins->left=perm;
}
else
{
temp=head;
while(temp!=NULL)
{
flag=1;
break;
}
}
if(flag==1)
perm->right=ins;
ins->left=perm;
temp->left=ins;
}
cout<<”\n\t\t\t element not found”;
}
void dll::dele()
{
flag=0;
if (head==NULL)
{
cout”\n\t\t\t list is empty so unable to delete:”;
return:
}
else
{
cout<<”\n\t\t\t which to delete:”;
cin>>da1;
cout<<da1;
if(head->data==da1)
head=head->right
else
temp=head;
while(temp->data==da1)
{
perm=temp;
temp=temp->right;
if(temp->data==da1)
{
flag=1;
break;
}
}
if(flag==1)
{
temp1=temp->right;
perm->right=temp1;
}
else
cout<<”\n\t\t\t element not found”;
}
}
}
void dll::display(node *head)
{
temp=head;
cout<<”\n\t\t\t doubly linked list look as follows:”;
cout<<”\n\t\t\t”;
while(temp!=NULL)
{
cout<<temp->data<<”<-->”;
temp=temp->right;
}
}
void main()
{
dll d;
int choice;
clrscr();
cout<<”\n\t\t\t creation, insertion and deletion in doubly linked list”;
cout<<”\n\t\t\t ………………………………………………………….”;
do
{
cout<<”\n\t\t\t 1-CREATION”;
cout<<”\n\t\t\t 2-INSERTION”;
cout<<”\n\t\t\t 3-DELETION”;
cout<<”\n\t\t\t 4-EXIT”;
cout<<”\n\t\t\t ENTER YOUR CHOICE:”;
cin>>choice;
cout<<choice;
switch(choice)
{
case 1:d. create();
d.display(head);
break;
case 2:d. insert();
d.display(head);
break;
case 3:d. dele();
d.display(head);
break;
case 4:break;
}
}
while(choice!=4);
getch();
}
OUTPUT (CREATION, INSERTION, AND DELETION IN DLL)
**********************************************************
1-CREATION
2-INSERTION
3-DELETION
4-EXIT
ENTER YOUR CHOICE: 1
ENTER THE DATA: 10
DOUBLY LINKED LIST LOOK AS FOLLOWS:
10<--> NULL
1-CREATION
2-INSERTION
3-DELETION
4-EXIT
ENTER YPOUR CHOICE: 2
BEFORE WHICH ELEMENT TO INSERT (PRESS 0 TO ADD AT END): 0
INSERT THE DATA: 20
DOUBLY LINKED LIST LOOK AS FOLLOWS:
10<-->20< -->NULL
1-CREATION
2-INSERTION
3-DELETION
4-EXIT
ENTER YOUR CHOICE:2
BEFORE WHICH ELEMENT TO INSERT ( PRESS 0 TO ADD AT END ):
10
INSERT THE DATA:5
DOUBLY LINKED LIST LOOK AS FOLLOWS:
5< -- >10< -->20< -- >NULL
1-CREATION
2-INSERTION
3-DELETION
4-EXIT
ENTER YOUR CHOICE: 2
BEFORE WHICH ELEMENT TO INSERT (PRESS 0 TO ADD AT END): 20
INSERT THE DATA: 15
DOUBLY LINKED LIST LOOK AS FOLLOWS:
5< -- >10<-->15<-->20<-->NULL
14. BINARY TREE TRAVERSALS (IN-ORDER, PRE-ORDER,
********************************************************
POST-ORDER) USING LINKED LISTS.
************************************
PROGRAM:
#include<iostream.h>
#include<conio.h>
struct Node
{
int data;
struct Node *left, *right;
Node (int data)
{
this->data=data;
left=right=NULL;
}
};
void Postorder(struct Node* node)
{
if(node==NULL)
return;
Postorder(node->left);
Postorder(node->right);
cout<<node->data<<” “ ;
}
void Inorder(struct Node* node)
{
if(node==NULL)
return;
Inorder( node->left);
cout<<node->data<< “ “ ;
Inorder(node->right);
}
void Preorder(struct Node* node)
{
if (node==NULL)
return;
cout<<node->data<<” “ ;
Preorder(node->left);
Preorder(node->right);
}
int main()
{
struct Node* root=new Node(1);
root->left=new Node(2);
root->right=new Node(3);
root->left->left=new Node(4);
root->left->right=new Node(5);
cout<<”\n Preorder traversal of binary tree is \n “ ;
Preorder(root);
cout<<”\n Inorder traversal of binary tree is \n” ;
Inorder(root);
cout<<”\n Postorder traversal of binary tree is \n”;
Postorder(root);
return 0;
}
OUTPUT: (BINARY TREE TRAVERSALS)
****************************************
Preorder traversal of binary tree is
12453
Inorder traversal of binary tree is
42513
Postorder traversal of binary tree is
45231
15 a. Program to implement Depth First Search for Graph using Recursion
****************************************************************
PROGRAM:
#include<iostream.h>
class graph
{
int a[10][10],n,start;
public:
void getdata();
void dfs_traverse();
};
void graph::getdata()
{
cout<<"Enter the number of vertices in the graph ";
cin>>n;
cout<<"Enter the adjacency matrix of graph "<<endl;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
cin>>a[i][j];
cout<<"Enter the vertex from which you want to traverse ";
cin>>start;
}
void graph::dfs_traverse()
{
int *visited= new int[n];
int stack[10],top=-1,i;
for(int j=0;j<n;j++)
visited[j]=0;
cout<<"The Depth First Search Traversal : "<<endl;
i=stack[++top]=start;
visited[start]=1;
while(top>=0)
{
i=stack[top];
cout<<stack[top--]<<endl;
for(int j=n-1;j>=0;j--)
if(a[i][j]!=0&&visited[j]!=1)
{
stack[++top]=j;
visited[j]=1;
}
}
}
int main()
{
graph dfs;
dfs.getdata();
dfs.dfs_traverse();
return 0;
}
OUTPUT (DEPTH FIRST SEARCH)
********************************
Enter the number of vertices in the graph 5
Enter the adjacency matrix of graph
01100
10010
10011
01100
00110
Enter the vertex from which you want to traverse 0
The depth first search traversal:
0
1
3
2
4
Process returned 0 (0*0) execution time:26.410s
15 b.Program to implement Breadth First Search for Graph using
********************************************************
Recursion
*********
PROGRAM:

#include<iostream>
class graph
{
int a[10][10],n,start;
public:
void getdata();
void bfs_traverse();
};
void graph::getdata()
{
cout<<"Enter the number of vertices in the graph ";
cin>>n;
cout<<"Enter the adjacency matrix of graph "<<endl;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
cin>>a[i][j];
cout<<"Enter the vertex from which you want to traverse ";
cin>>start;
}
void graph::bfs_traverse()
{
int *visited= new int[n];
int queue[10],front=-1,rear=0,i;
for(int j=0;j<n;j++)
visited[j]=0;
cout<<"Traversing the graph using breadth first search algorithm : "<<endl;
queue[rear]=start;
visited[start]=1;
while(front!=rear)
{
cout<<queue[++front]<<endl;
i=queue[front];
for(int j=0;j<n;j++)
if(a[i][j]!=0&&visited[j]!=1)
{
queue[++rear]=j;
visited[j]=1;
}
}
}
int main()
{
graph bfs;
bfs.getdata();
bfs.bfs_traverse();
return 0;
}
OUTPUT:

(BREADTH FIRST SEARCH)


************************************
Enter the number of vertices in the graph 5
Enter the adjacency matrix of graph
01100
10010
10011
01100
00110
Enter the vertex from which you want to traverse 1
Traversing the grap using breadth first search algorithm:
1
0
3
2
4
Process returned 0 (0*0) execution time:33.287s

You might also like