You are on page 1of 70

DATA STRUCTURES LAB SYLLABUS Exercise 1: Write recursive programme which computes the nth Fibonacci number, for

appropriate values of n. Analyze behaviour of the programme obtain the frequency count of the statement for various values of n. Exercise 2: Write recursive programme for the following a) Write recursive C program for calculation of Factorial of an integer b) Write recursive C program for calculation of GCD (n, m) c) Write recursive C program for Towers of Hanoi : N disks are to be transferred from peg S to peg D with Peg I as the intermediate peg. Exercise 3: a) Write C programs that use both recursive and non recursive functions to perform Linear search for a Key value in a given list. b) Write C programs that use both recursive and non recursive functi ons to perform Binary search for a Key value in a given list. c) Write C programs that use both recursive and non recursive functions to perform Fibonacci search for a Key value in a given list. Exercise 4: a) Write C programs that implement Bubble sort, to sort a given list of integers in ascending order b) Write C programs that implement Quick sort, to sort a given list of integers in ascending order c) Write C programs that implement Insertion sort, to sort a given list of integers in ascending order Exercise 5: a) Write C programs that implement heap sort, to sort a given list of integers in ascending order b) Write C programs that implement radix sort, to sort a given list of integers in ascending order c) Write C programs that implement merge sort, to sort a given list of integers in ascending order Exercise 6: a) Write C programs that implement stack (its operations) using arrays b) Write C programs that implement stack (its operations) using Linked list

Exercise 7: a) Write a C program that uses Stack operations to Convert infix expression into postfix expression b) Write C programs that implement Queue (its operations) using arrays. c) Write C programs that implement Queue (its operations) using linked lists Exercise 8: a) Write a C program that uses functions to create a singly linked list b) Write a C program that uses functions to perform insertion operation on a singly linked list c) Write a C program that uses functions to perform deletion operation on a singly linked list Exercise 9: a)Adding two large integers which are represented in linked list fashion. b)Write a C program to reverse elements of a single linked list. c)Write a C program to store a polynomial expression in memory using linked list d) Write a C program to representation the given Sparse matrix using arrays. e) Write a C program to representation the given Sparse matrix using linked list Exercise10: a) Write a C program to Create a Binary Tree of integers b) Write a recursive C program, for Traversing a binary tree in preorder, inorder and postorder. c) Write a non recursive C program, for Traversing a binary tree in preorder, inorder and postorder. d) Program to check balance property of a tree. Exercise 11: a) Write a C program to Create a BST b) Write a C program to insert a node into a BST. c) Write a C program to delete a node from a BST. Exercise 12: a) Write a C programme to compute the shortest path of a graph using Dijkstras algorithm b) Write a C programme to find the minimum spanning tree using Warshalls Algorithm

EXERCISE 1:Write recursive programme which computes the nth Fibonacci number, for appropriate values of n. Analyze behaviour of the programme Obtain the frequency count of the statement for various values of n. PROGRAM: #include<stdio.h> #include<conio.h> int fn; int main(void) { int p,N; int fib(int); clrscr(); printf("Enter the fibonacci number position you required:"); scanf("%d",&p); if(p<=0) { printf("Imposible to generate the Fibonacci series"); getch(); return; } N=fib(p-1); printf("Fibonacci number at position %d is %d",p,N); getch(); } int fib(int n) { if(n==1|| n==0) return n; fn=fib(n-1)+fib(n-2); return(fn); } OUTPUT: Enter the fibonacci number position you required: 5 Fibonacci number at position 5 is 3

EXERCISE 2: Write recursive programme for the following a) Write recursive C program for calculation of Factorial of an integer b) Write recursive C program for calculation of GCD (n, m) c) Write recursive C program for Towers of Hanoi : N disks are to be transferred from peg S to peg D with Peg I as the intermediate peg. PROGRAM: a) Write recursive C program for calculation of Factorial of an integer. /* factorial of a number (recursive functions) */

#include <stdio.h> #include <conio.h> main() { unsigned int n; unsigned long int r; unsigned long int fact_rec(unsigned int); clrscr(); printf("\n------FACTORIAL OF A NUMBER------\n"); printf("\n enter a number (positive integer) \t"); scanf("%u",&n); r=fact_rec(n); printf("\n\nfactorial (recursive function) of %u is %lu",n,r); getch(); } unsigned long int fact_rec(unsigned int n) { if(n==0) return(1); else return(n*fact_rec(n-1)); } OUTPUT: ------FACTORIAL OF A NUMBER-----enter a number (positive integer) 5

factorial (recursive function) of 5 is 120 PROGRAM: b) Write recursive C program for calculation of GCD (n, m) /* gcd of two numbers (recursive function) */

#include <stdio.h> #include <conio.h> main()

{ int m,n,r; int gcd_rec(int,int); clrscr(); printf("\n-------GCD OF TWO NUMBERS------\n"); printf("\n enter two integers \t"); scanf("%d%d",&m,&n); r=gcd_rec(m,n); printf("\n\n gcd (recursive function) of %d and %d is %d",m,n,r); getch(); } int gcd_rec(int m,int n) { int dn,ds,d; if(m>n) { dn=m; ds=n; } else { dn=n; ds=m; } d=dn%ds; if(d==0) return(ds); else return(gcd_rec(ds,d)); } OUTPUT: -------GCD OF TWO NUMBERS-----enter two integers 4 16

gcd (recursive function) of 4 and 16 is 4

PROGRAM: c) Write recursive C program for Towers of Hanoi : N disks are to be transferred from peg S to peg D with Peg I as the intermediate peg. /* Towers of Hanoi problem (recursive function) */

#include <stdio.h> #include <conio.h> main() {

} /* Recursive Function */ void rec_hanoi( int nd,char p1, char p2, char p3) { if ( nd == 1 ) { printf( "\nMove top disk from peg %c to peg %c", p1, p2 ); return; } rec_hanoi( nd - 1,p1, p3, p2 ); printf( "\nMove top disk from peg %c to peg %c", p1, p2 ); rec_hanoi( nd - 1,p3, p2, p1 ); return; } OUTPUT: enter number of disks 3 towers of hanoi problem (recursive function) Move top disk from peg S to peg D Move top disk from peg S to peg I Move top disk from peg D to peg I Move top disk from peg S to peg D Move top disk from peg I to peg S Move top disk from peg I to peg D Move top disk from peg S to peg D EXERCISE 3:

int nd; void rec_hanoi(int,char,char,char); clrscr(); printf("\nenter number of disks\t"); scanf("%d",&nd); if(nd<=0) { printf("\n cannot move disks invalid data"); getch(); return(1); } printf("\n towers of hanoi problem (recursive function)\n "); rec_hanoi(nd,'S','D','I'); getch();

a) Write C programs that use both recursive and non recursive functions to perform Linear search for a Key value in a given list. b) Write C programs that use both recursive and non recursiv e functions to perform Binary search for a Key value in a given list. c) Write C programs that use both recursive and non recursive functions to perform Fibonacci search for a Key value in a given list. PROGRAM: a) Write C programs that use both recursive and non recursive functions to perform Linear search for a Key value in a given list. /* Program for linear search*/ #include <stdio.h> #include <conio.h> #define M 30 int nonrec_linear(int [],int,int); int rec_linear(int [],int,int); void show(int ,int); int nc=0; int size=0; int main(void) { int a[M],n,i,item,pos=-1; clrscr(); printf("\n--------LINEAR SEARCH---------\n"); printf("\n enter number of elements\t"); scanf("%d",&n); size=n; printf("\n enter %d integers\n",n); for(i=0;i<n;i++) scanf("%d",&a[i]); printf("\n enter item to be found\t"); scanf("%d",&item); printf("\n elements in list \n"); for(i=0;i<n;i++) printf("%3d ",a[i]); printf("\n Non recursive"); pos=linear(a,n,item);

show(item,pos); nc=0; printf("\n Recursive"); pos=rec_linear(a,0,item); show(item,pos); getch(); return(0); } int linear(int a[M],int n, int item) { int i; for(i=0;i<n;i++) { nc++; if(a[i] == item) return(i); } return(-1); } int rec_linear(int a[M],int i,int item) { if(i==size) { return(-1); } else if(a[i]==item) { nc++; return(i); } else { nc++; return(rec_linear(a,i+1,item));

} } void show(int item,int pos) { if(pos==-1) printf("\n element %d not found in the list",item); else { printf("\n element %d found at pos %d in list",item,pos); printf("\n number of comparisions %d",nc); } } OUTPUT: --------LINEAR SEARCH--------enter number of elements enter 5 integers 46251 enter item to be found 1 elements in list 4 6 2 5 1 Non recursive element 1 found at pos 4 in list number of comparisions 5 Recursive element 1 found at pos 4 in list number of comparisions 5 5

PROGRAM: b) Write C programs that use both recursive and non recursive functions to perform Binary search for a Key value in a given list. /* binary search (recursive and nonrecursive functions) */

#include <stdio.h> #include <conio.h>

#define M 30 int nonrec_bin(int [],int,int); int rec_bin(int [],int,int,int); void show(int,int); int nc=0; main() { int a[M],n,i,item,pos=-1; clrscr(); printf("\n -------BINARY SEARCH-------\n"); printf("\n enter number of elements\t"); scanf("%d",&n); printf("\n enter %d integers\n",n); for(i=0;i<n;i++) scanf("%d",&a[i]); printf("\n enter item to be found \t"); scanf("%d",&item); printf("\n elements in list \n"); for(i=0;i<n;i++) printf("%3d ",a[i]); printf("\n\n binary search (non-recursive function)"); pos=nonrec_bin(a,n,item); show(pos,item); nc=0; pos=-1;

printf("\n\n binary search (recursive function)"); pos=rec_bin(a,0,n-1,item); show(pos,item); getch(); return(1); } void show(int pos,int item) { if(pos==-1) printf("\n element %d not found in the list",item); else printf("\n element %d found at position %d",item,pos); printf("\n number of comparisions %d",nc); return; } int nonrec_bin(int a[M],int n, int item) { int i,beg=0,end=n-1,mid; nc=0; while(beg<=end) { nc++; mid=(beg+end)/2; if(item == a[mid]) return(mid);

else if(item < a[mid]) end=mid-1; else beg= mid+1; } return(-1); } int rec_bin(int a[M],int beg,int end,int item) { int mid=0; if(beg<=end) { nc++; mid=(beg+end)/2; if( item == a[mid]) return (mid); else if(item < a[mid]) return( rec_bin(a,beg,mid-1,item) ); else return( rec_bin(a,mid+1,end,item) ); } return(-1); } OUTPUT: -------BINARY SEARCH-------

enter number of elements enter 9 integers 11 22 33 44 55 66 77 88 99 enter item to be found elements in list 11 22 33 44 55 66

88 77 88 99

binary search (non-recursive function) element 88 found at position 7 number of comparisions 3 binary search (recursive function) element 88 found at position 7 number of comparisions 3 Exercise 4: a) Write C programs that implement Bubble sort, to sort a given list of integers in ascending order b) Write C programs that implement Quick sort, to sort a given list of integers in ascending order c) Write C programs that implement Insertion sort, to sort a given list of integers in ascending order PROGRAM: a) Write C programs that implement Bubble sort, to sort a given list of integers in ascending order /*a) Implementation of bubblesort */

#include<stdio.h> #include<conio.h> main() { int a[100],n,i; clrscr(); printf("\n Enter number of elements:"); scanf("%d",&n); printf("\n Enter the elements:"); for(i=0;i<n;i++) scanf("%d",&a[i]); printf("\n Elements in the list before sorting:\n"); for(i=0;i<n;i++) printf("%3d",a[i]); bubblesort(a,n); printf("\n Elements in the list after sorting:\n"); for(i=0;i<n;i++)

} bubblesort(int a[], int n) { int temp,i,j; for(i=0;i<(n-1);i++) { for(j=0;j<n-(i+1);j++) { if(a[j]>a[j+1]) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } } } OUTPUT: Enter number of elements:5 Enter the elements:3 6 4 9 1 Elements in the list before sorting: 3 6 4 9 1 Elements in the list after sorting: 1 3 4 6 9 PROGRAM: b) Write C programs that implement Quick sort, to sort a given list of integers in ascending order /* implementation of quicksort #include<stdio.h> #include<conio.h> void quicksort(int[],int,int); void swap(int*,int*); main() { int a[30],i,n; clrscr(); printf("\n Enter number of elements:"); scanf("%d",&n); printf("\n Enter the elements:"); for(i=0;i<n;i++) scanf("%d",&a[i]); */

printf(" %5d ",a[i]); getch();

printf("\n Elements in the list before sorting:\n"); for(i=0;i<n;i++) printf("%3d",a[i]); quicksort(a,0,n-1); printf("\n Elements in the list after sorting:\n"); for(i=0;i<n;i++) printf(" %5d ",a[i]); getch(); } void quicksort(int a[],int m,int n) { int key,i,j; if(m<n) { key=a[m]; i=m+1; j=n; while(i<=j) { while((i<=n)&&(a[i]<=key)) i++; while((j>=m)&&(a[j]>key)) j--; if(i<j) swap(&a[i],&a[j]); } swap(&a[m],&a[j]); quicksort(a,m,j-1); quicksort(a,j+1,n); } } void swap(int *m,int *n) { int temp; temp=*m; *m=*n; *n=temp; } OUTPUT: Enter number of elements:5 Enter the elements:3 6 4 9 1 Elements in the list before sorting: 3 6 4 9 1 Elements in the list after sorting: 1 3 4 6 9

PROGRAM: c) Write C programs that implement Insertion sort, to sort a given list of integers in ascending order.

/* implementation of insertionsort */ #include<stdio.h> #include<conio.h> main() { int a[30],i,j,t,a[10],n,p=0; clrscr(); printf("\n Enter number of elements:"); scanf("%d",&n); printf("\n Enter the elements:"); for(i=0;i<n;i++) scanf("%d",&a[i]); printf("\n Elements in the list before sorting:\n"); for(i=0;i<n;i++) printf("%3d",a[i]); for(i=1;i<n;i++) { t=a[i]; for(p=i;((p>0)&&(a[p-1]>t));p--) a[p]=a[p-1]; a[p]=t; } printf("\n Elements in the list after sorting:\n"); for(i=0;i<n;i++) printf(" %5d ",a[i]); getch(); } OUTPUT: Enter number of elements:5 Enter the elements:3 6 4 9 1 Elements in the list before sorting: 3 6 4 9 1 Elements in the list after sorting: 1 3 4 6 9

Exercise 5: a) Write C programs that implement heap sort, to sort a given list of integers in ascending order b) Write C programs that implement radix sort, to sort a given list of integers in ascending order c) Write C programs that implement merge sort, to sort a given list of integers in ascending order. PROGRAM: a) Write C programs that implement heap sort, to sort a given list of integers in ascending order. /* program for implementing HEAP SORT*/ #include<stdio.h> #include<conio.h> int x[100],size,i; void main() { void buildheap(),heapsort(); clrscr(); printf("\n enter how mwny elements do you want to sort: "); scanf("%d",&size); printf("\n enter %d elements\t",size); for(i=1;i<=size;++i) scanf ("%d",&x[i]); buildheap(); heapsort(); printf("\n sorted elements are: \n"); for(i=1;i<=size;++i) printf("%5d",x[i]); getch(); } void buildheap() { int j,k,temp; for(k=2;k<size;++k) { i=k; temp=x[k]; j=i/2; while((i>1)&&(temp>x[j])) { x[i]=x[j]; i=j;

j=i/2; if(j<1) j=1; } x[i]=temp; } } void heapsort() { int j,k,temp,value; for(k=size;k>=2;--k) { temp=x[1]; x[1]=x[k]; x[k]=temp; i=1; value=x[1]; j=2; if((j+1)<k) if(x[j+1]>x[j]) j++; while((j<=(k-1))&&(x[j]>value)) { x[i]=x[j]; i=j; j=2*i; if((j+1)<k) if(x[j+1]>x[j]) j++; else if(j>size) j=size; x[i]=value; } } } OUTPUT: enter how mwny elements do you want to sort: 4 enter 4 elements 5831

sorted elements are:

PROGRAM: b)Write C programs that implement radix sort, to sort a given list of integers in ascending order /* program for implementing RADIX SORT*/ #include<stdio.h> #include<conio.h> #include<math.h> main() { int a[100][100],r=0,c=0,i,sz,b[50],temp; clrscr(); printf("Enter the size of the array: "); scanf("%d",&sz); printf("\n"); for(r=0;r<100;r++) { for(c=0;c<100;c++) a[r][c]=1000; } for(i=0;i<sz;i++) { printf("Enter the %d element: ",i+1); scanf("%d",&b[i]); r=b[i]/100; c=b[i]%100; a[r][c]=b[i]; } printf("\n The elements ater sorting are\t"); for(r=0;r<100;r++) { for(c=0;c<100;c++) { for(i=0;i<sz;i++) { if(a[r][c]==b[i]) { printf("%5d",a[r][c]); } } } } getch(); } OUTPUT:

Enter the size of the array: 5 Enter the Enter the Enter the Enter the Enter the 1 element: 2 element: 3 element: 4 element: 5 element: 9 8 7 5 6 5 6 7 8 9

The elements ater sorting are

PROGRAM: c) Write C programs that implement merge sort, to sort a given list of integers in ascending order. /* program for implementing MERGE SORT*/ #include<stdio.h> #include<conio.h> #define M 30 void mergesort(int[],int,int); void merge(int[],int,int,int); main() { int a[M],i,n; clrscr(); printf("enter number of elements into array"); scanf("%d",&n); printf("enter %d elements:",n); for(i=0;i<n;i++) scanf("%d",&a[i]); mergesort(a,0,n-1); printf("elements after sorting are: \n"); for(i=0;i<n;i++) printf("%3d",a[i]); getch(); } void mergesort(int a[],int low, int high) { int mid; if(low<high) { mid=(low+high)/2; mergesort(a,low,mid); mergesort(a,mid+1,high); merge(a,low,high,mid); } } void merge(int a[],int low,int high,int mid) { int i,j,k,c[50]; i=low;

j=mid+1; k=low; while((i<=mid)&&(j<=high)) { if(a[i]<a[j]) { c[k]=a[i]; k++; i++; } else { c[k]=a[j]; k++; j++; } } while(i<=mid) { c[k]=a[i]; k++; i++; } while(j<=high) { c[k]=a[j]; k++; j++; } for(i=low;i<k;i++) { a[i]=c[i]; } } OUTPUT: enter number of elements into array5 enter 5 elements:3 9 6 1 4 elements after sorting are: 1 3 4 6 9 EXERCISE 6: a) Write C programs that implement stack (its operations) using arrays b) Write C programs that implement stack (its operations) using Linked list PROGRAM: a) Write C programs that implement stack (its operations) using arrays /*a) Implementation of STACK using ARRAYS */ #include<stdio.h>

#include<conio.h> #define MAX 100 int st_arr[20]; int t=-1; void push_ele(int ele); int pop_ele(); void display_ele(); main() { int choice,num1=0,num2=0; clrscr(); printf("---------"); printf("\n\t\t MENU"); printf("\n============="); printf("\n [1] using push_function"); printf("\n [2] using pop_function"); printf("\n [3]elements present in stack"); printf("\n [4] exit \n"); while(1) { printf("\n enter your choice:\t"); fflush(stdin); scanf("%d",&choice); switch(choice) { case 1: printf("\n element to be pushed: "); scanf("%d",&num1); push_ele(num1); break; case 2: num2=pop_ele(); printf("\n element to be poped : %d", num2); getch(); break;

case 3: display_ele(); getch(); break; case 4: exit(1); break; default: printf("your choice invalid \n"); break; } } } /* implementing the push function */ void push_ele(int ele) { if(t==MAX-1) { printf("stack is full \n"); getch(); exit(1); } st_arr[++t]=ele; } /* implementing the pop function */ int pop_ele() { int ele1; if(t==-1) { printf("\n stack is empty \n"); getch(); exit(1); } return(st_arr[t--]); }

/* implementing display function*/ void display_ele() { int k; printf("\n elements present in the stack are: \n"); for(k=0;k<=t;k++) printf("%d\t", st_arr[k]); } OUTPUT: --------MENU ============= [1] using push_function [2] using pop_function [3]elements present in stack [4] exit

enter your choice:

element to be pushed: 501

enter your choice:

element to be pushed: 502

enter your choice:

element to be pushed: 503

enter your choice:

element to be poped : 503 enter your choice: 3

elements present in the stack are: 501 502 4

enter your choice:

PROGRAM: b) Write Linked Lists

C programs that implement stack (its operations) using

/*b) Implementation of STACK using LINKEDLISTS*/ #include<stdio.h> #include<conio.h> struct st_point { int ele; struct st_point *l; } *t; int i; void push_ele(int j); int pop_ele(); void display_ele(); main() { int choice,num1=0,num2=0; int i; clrscr(); printf("---------"); printf("\n\t\t MENU"); printf("\n============="); printf("\n [1] using push_function"); printf("\n [2] using pop_function"); printf("\n [3]elements present in stack"); printf("\n [4] exit \n"); while(1) { printf("\nenter your choice:\t"); fflush(stdin); scanf("%d",&choice); switch(choice) { case 1: printf("\n element to be pushed: ");

scanf("%d",&num1); push_ele(num1); break; case 2: num2=pop_ele(1); printf("\n element to be poped : %d", num2); getch(); break; case 3: printf("\n elements present in the stacked are:"); display_ele(); getch(); break; case 4: exit(1); break; default: printf("your choice invalid \n"); break; } } } /* implementing the push function */ void push_ele(int j) { struct st_point *m; m=(struct st_point*)malloc(sizeof( struct st_point)); m->ele=j; m->l=t; t=m; return; } /* removing the elements in the pop function */ int pop_ele() { if(t==NULL) { printf("\n stack is empty \n"); getch(); exit(1); } else { int i=t->ele; t=t->l; return(i); } } /* Displaying the elements */ void display_ele() { struct st_point *pointer=NULL; pointer=t;

while(pointer!=NULL) { printf("%d \t", pointer->ele); pointer=pointer->l; } } OUTPUT: --------MENU ============= [1] using push_function [2] using pop_function [3]elements present in stack [4] exit

enter your choice:

element to be pushed: 501

enter your choice:

element to be pushed: 502

enter your choice:

element to be pushed: 503

enter your choice:

element to be poped : 503

enter your choice:

elements present in the stack are: 501 502 4

enter your choice: Exercise 7:

a) Write a C program that uses Stack operations to Convert infix expression into postfix expression b) Write C programs that implement Queue (its operations) using arrays. c) Write C programs that implement Queue (its operations) using linked lists PROGRAM: a)Write a C program that uses Stack operations to Convert infix expression into postfix expression /* infix expression to postfix expression conversion */

#include <stdio.h> #include <conio.h> #include <process.h> #define M 20 typedef struct { int top; char item[M]; }STACK; void infx_pofx(char [],char []); int prcd(char); void push(STACK *,char); char pop(STACK *); main() { char infx[M],pofx[M]; clrscr();

printf("\n enter infix expression\t"); fflush(stdin); gets(infx); infx_pofx(infx,pofx); printf("\n postfix expression is getch(); return(1); } void infx_pofx(char infx[M],char pofx[M]) { int ip,op=0; char c; STACK opsk={-1,{'\0'}}; %s",pofx);

for(ip=0; (c=infx[ip])!='\0'; ip++) { switch(c) { case '(': push(&opsk,c); break; case ')': while( opsk.item[opsk.top] != '(') pofx[op++]=pop(&opsk); opsk.top--; break; case '*': case '/': case '+': case '-': if(opsk.top == -1) push(&opsk,c);

else { while( prcd(opsk.item[opsk.top]) >= prcd(c) ) pofx[op++]=pop(&opsk); push(&opsk,c); } break; default: pofx[op++]=c; } } while(opsk.top != -1) pofx[op++]=pop(&opsk); pofx[op]='\0'; return; } int prcd(char opr) { switch(opr) { case '^': return(3); case '/': case '*': return(2); case '+': case '-': return(1); default: return(0); } } void push(STACK *ps,char c) {

if(ps->top == M-1) { printf("\n stack full"); getch(); exit(1); } ps->item[++(ps->top)]=c; return; } char pop(STACK *ps) { if(ps->top == -1) { printf("\n stack empty"); getch(); exit(1); } return( ps->item[(ps->top)--]); }

OUTPUT: enter infix expression postfix expression is enter infix expression postfix expression is a+b*c-d*e abc*+de*(a+b)*(c-d) ab+cd-*

PROGRAM: b)Write C programs that implement Queue (its operations) using arrays /* static implementation of queue using arrays */

#include <stdio.h>

#include <conio.h> #define M 30 typedef struct { int item[M]; int rear,front; }QUE; void insert(QUE *,int); int delete(QUE *); void display(QUE ); main() { QUE q={ {0},-1,-1}; int ch,n; clrscr(); printf("\n ------static implementation of queue using arrays-------"); do { printf("\n\n 1.insert \n 2.delete \n 3.display \n 4.quit"); printf("\n enter your choice\t"); scanf("%d",&ch); switch(ch) { case 1: printf("\n enter element to insert\t"); scanf("%d",&n); insert(&q,n); break; case 2: n=delete(&q); printf("\n deleted element is %d",n);

break; case 3: display(q); break; case 4: return(0); default: printf("\n invalid choice \a "); } }while(1); } void insert(QUE *pq,int n) { if(pq->rear > M-1) { printf("\n queue full \a"); getch(); exit(1); } pq->item[++pq->rear]=n; if(pq->front==-1) pq->front=0; return; } int delete(QUE *pq) { int n; if(pq->front == -1) { printf("\n queue empty \a"); getch(); exit(1);

} n=pq->item[pq->front]; if(pq->front==pq->rear) pq->front=pq->rear=-1; else pq->front++; return(n); } void display(QUE q) { int i; if(q.front == -1) printf("\n queue empty \a"); else { printf("\n queue contents\n"); printf("\n FRONT"); for(i=q.front;i<=q.rear;i++) printf("%5d",q.item[i]); printf(" REAR"); } return; } OUTPUT: ------static implementation of queue using arrays------1.insert 2.delete 3.display 4.quit

enter your choice

1 11

enter element to insert 1.insert 2.delete 3.display 4.quit enter your choice 1

enter element to insert 1.insert 2.delete 3.display 4.quit enter your choice 1

22

enter element to insert 1.insert 2.delete 3.display 4.quit enter your choice 3

33

queue contents FRONT 11 22 33 REAR 1.insert 2.delete 3.display 4.quit enter your choice 2

deleted element is 11 1.insert

2.delete 3.display 4.quit enter your choice queue contents FRONT 22 33 REAR 1.insert 2.delete 3.display 4.quit enter your choice 4 3

PROGRAM: c) Write C programs that implement Queue (its operations) using linked lists /* dynamic queue implementation using linked lists */

#include <stdio.h> #include <conio.h> struct queue { int item; struct queue *next; }; typedef struct queue QUE; QUE *front,*rear; void insert(QUE **,QUE **,int); int delete(QUE **,QUE **); void display(QUE *,QUE *); main() {

int ch,n; front=rear=NULL; clrscr(); printf("\n ------dynamic implementation of queue using linked lists-------"); do { printf("\n\n 1.insert \n 2.delete \n 3.display \n 4.quit"); printf("\n enter your choice\t"); scanf("%d",&ch); switch(ch) { case 1: printf("\n enter element to insert\t"); scanf("%d",&n); insert(&rear,&front,n); break; case 2: n=delete(&rear,&front); printf("\n deleted element is %d",n); break; case 3: display(rear,front); break; case 4: return(0);

default: printf("\n invalid choice \a "); } }while(1); } void insert(QUE **prear,QUE **pfront,int n)

{ QUE *node; node=(QUE*)calloc(1,sizeof(QUE)); if(node==NULL) { printf("\n memory full unable to create node \a"); getch(); exit(1); } node->item=n; node->next=NULL; if( *prear == NULL) *prear=*pfront=node; else { (*prear)->next=node; *prear= (*prear)->next; } return; } int delete(QUE **prear,QUE **pfront) { int n; QUE *temp; if(*pfront == NULL) { printf("\n queue empty \a");

getch(); exit(1); } n=(*pfront)->item; temp=*pfront; if(*pfront == *prear) *pfront=*prear=NULL; else *pfront=(*pfront)->next; free(temp); return(n); } void display(QUE *rear,QUE *front) { QUE *temp; if(front == NULL) printf("\n queue empty \a"); else { printf("\n queue contents\n"); printf("FRONT->"); for(temp=front;temp!=rear->next;temp=temp->next) printf("%5d",temp->item); printf(" <-REAR"); } return; }

OUTPUT: ------dynamic implementation of queue using linked lists------1.insert 2.delete 3.display 4.quit enter your choice 1 11

enter element to insert 1.insert 2.delete 3.display 4.quit enter your choice 1

enter element to insert 1.insert 2.delete 3.display 4.quit enter your choice 1

22

enter element to insert 1.insert 2.delete 3.display 4.quit enter your choice queue contents 3

33

FRONT-> 11 22 33 <-REAR

1.insert 2.delete 3.display 4.quit enter your choice 2

deleted element is 11 1.insert 2.delete 3.display 4.quit enter your choice queue contents FRONT-> 22 33 <-REAR 1.insert 2.delete 3.display 4.quit enter your choice EXERCISE 8: a) Write a C program that uses functions to create a singly linked list b) Write a C program that uses functions to perform insertion operation on a singly linked list c) Write a C program that uses functions to perform deletion operation on a singly linked list PROGRAM: /* singly linked list creation, insertion, deletion */ 4 3

#include <stdio.h> #include <conio.h>

#include <stdlib.h> struct node { int item; struct node *next; }; typedef struct node NODE; NODE* create(void); int insert(NODE *,int); int delete(NODE *,int); void display(NODE *); int main(void) { NODE *start=NULL; int ch; int n; clrscr(); printf("\n ------SINGLY LINKED LIST-------"); do { printf("\n\n 1.creation \n 2.insertion \n 3.deletion \n 4.display \n 5.quit"); printf("\n enter your choice\t"); scanf("%d",&ch); switch(ch) { case 1: start=create();

if(start==NULL) printf("\n unable to create singly linked list"); else { printf("\n singly linked list created \n"); display(start); } break; case 2: printf("\n enter integer to insert at the end \t"); scanf("%d",&n); if( insert(start,n) == 0) printf("\n %d is successfully inserted ",n); else printf("\nerror while inserting %d",n); break; case 3: printf("\n enter integer to delete from the list\t"); scanf("%d",&n); if( delete(start,n)== 0) printf("\n %d is successfully deleted from list",n); else printf("\n %d is not found in the list",n); break; case 4: display(start); break; case 5: return(0); default: printf("\n invalid choice \a "); }

}while(1); } NODE* create(void) { NODE *start=NULL,*node,*temp; char ch; do { node=(NODE *)calloc(1,sizeof(NODE)); if(node == NULL) { printf("\n unable to create node"); getch(); return(start); } else { printf("\n enter integer\t"); scanf("%d",&node->item); node->next=NULL; if(start == NULL) start = node; else { temp=start; while(temp->next!=NULL) temp=temp->next;

temp->next=node; } } printf("\n do u want to enter element [Y/N]\t"); fflush(stdin); ch=getche(); }while(ch=='y' || ch== 'Y'); return(start); } int insert(NODE *start,int n) { NODE *node,*temp; node=(NODE *)calloc(1,sizeof(NODE)); if(node==NULL) { printf("\n unable to create node"); getch(); return(1); } node->item=n; node->next=NULL; if(start==NULL) start=node; else { temp=start; while(temp->next!=NULL)

temp=temp->next; temp->next=node; } return(0); } int delete(NODE *start,int n) { NODE *temp,*prev; if(start==NULL) printf("\n singly linked list is empty"); else { temp=start; prev=temp; while(temp!=NULL) { if(temp->item == n) { prev->next=temp->next; free(temp); return(0); } prev=temp; temp=temp->next; } } return(1);

} void display(NODE *start) { NODE *temp; if(start == NULL) printf("\n singly linked list is empty \a"); else { printf("\n singly linked list contents \n"); printf("\n\tSTART"); for(temp=start;temp!=NULL;temp=temp->next) printf("->%d",temp->item); printf("->NULL"); } return; } OUTPUT: ------SINGLY LINKED LIST------1.creation 2.insertion 3.deletion 4.display 5.quit enter your choice enter integer 11 do u want to enter element [Y/N] enter integer 22 y 1

do u want to enter element [Y/N] singly linked list created singly linked list contents START->11->22->NULL 1.creation 2.insertion 3.deletion 4.display 5.quit enter your choice 2 9

enter integer to insert at the end 9 is successfully inserted 1.creation 2.insertion 3.deletion 4.display 5.quit enter your choice 4

singly linked list contents START->11->22->9->NULL 1.creation 2.insertion 3.deletion 4.display 5.quit enter your choice 3

enter integer to delete from the list 22

22 is successfully deleted from list 1.creation 2.insertion 3.deletion 4.display 5.quit enter your choice 4

singly linked list contents START->11->9->NULL 1.creation 2.insertion 3.deletion 4.display 5.quit enter your choice Exercise 9: a) Adding two large integers which are represented in linked list fashion. b) Write a C program to reverse elements of a single linked list. c) Write a C program to store a polynomial expression in memory using linked list d) Write a C program to representation the given Sparse matrix using arrays. e) Write a C program to representation the given Sparse matrix using linked list PROGRAM:a) Adding two large integers which are represented in linked list fashion. /* Adding two large integers using linked lists*/ #include<stdio.h> #include<alloc.h> #include<conio.h> #include<ctype.h> struct node { int data; 5

struct node*next; }; void insert(struct node**p,int num) { struct node*temp; if(*p==NULL) { (*p)=(struct node*)malloc(sizeof(struct node)); (*p)->next=NULL; (*p)->data=num; } else { temp=(struct node*)malloc(sizeof(struct node)); temp->next=(*p); (*p)=temp; (*p)->data=num; } } void add_in(struct node *a,struct node *b,struct node **c) { int d,carry=0; struct node *t; while(a!=NULL && b!=NULL) { d=(a->data+b->data+carry)%10; insert(c,d); if( (a->data+b->data+carry) >= 10) { carry=1; } else carry=0; a=a->next; b=b->next; } if(a==NULL&&b==NULL) { return; } else { if(a!=NULL&&b==NULL) t=a;

else { t=b; } while(t!=NULL) { d=(carry+t->data)%10; if(carry+t->data>=10) carry=1; else carry=0; insert(c,d); t=t->next; } if(carry==1) insert(c,carry); } } void numin(struct node**p) { char c='c'; *p=NULL; while(c!='n') { c=getch(); if(!isdigit(c)) return; else { putch(c); insert(p,c-'0'); } } } void disp(struct node*p) { if(p==NULL) return; else { printf("%d",p->data);

disp(p->next); } } void main() { struct node *a,*b,*c; clrscr(); a=b=c=NULL; printf("\nEnter the first number...."); numin(&a); printf("\nEnter the second number...."); numin(&b); printf("\nThe added result is..."); add_in(a,b,&c); disp(c); getch(); } OUTPUT: Enter the first number....111111111 Enter the second number....111111111 The added result is...222222222 PROGRAM: b) Write a C program to reverse elements of a single linked list. /* Reverse the elements of a single linked list*/ #include<stdio.h> #include<conio.h> #include<alloc.h> struct node { int data; struct node *next; }*start=NULL; void creat() { char ch; do { struct node *newnode, *current; newnode=(struct node*)malloc(sizeof(struct node)); printf("\nenter the data\n"); flushall();

scanf("%d",&newnode->data); newnode->next=NULL; if(start==NULL) { start=newnode; current=newnode; } else { current->next=newnode; current=newnode; } printf("\n do you want to continue::\n"); ch=getche(); }while(ch!='n'); } void display() { struct node *newnode; printf("the linked list ::"); newnode=start; while(newnode!=NULL) { printf("%d \t",newnode->data); newnode=newnode->next; } printf("NULL"); } void reverse() { struct node *preptr,*curptr,*temp; curptr=start; preptr=NULL; while(curptr!=NULL) { temp=preptr; preptr=curptr; curptr=curptr->next;

preptr->next=temp; } start=preptr; } void main() { clrscr(); creat(); printf("\nSingle Linked List data::\n"); display(); reverse(); printf("\n Reverse Linked List data::\n"); display(); getch(); } OUTPUT: enter the data 5 do you want to continue:: y enter the data 6 do you want to continue:: y enter the data 1 do you want to continue:: n Single Linked List data:: the linked list ::5 6 1 Reverse Linked List data:: the linked list ::1 6 5

NULL NULL

PROGRAM: d) Write a C program to representation the given Sparse matrix using arrays. /* Sparse matrix representation using arrays*/ #include<stdio.h> void main() { int a[10][10],s[10][10]; int i,j,m,n,k=0,l=0;

clrscr(); printf("\n Enter the no of rows: "); scanf("%d",&n); printf("\n Enter the no of columns: "); scanf("%d",&m); printf("\n Enter the elements in the array : "); for(i=0;i<n;i++) for(j=0;j<m;j++) scanf("%d",&a[i][j]); printf("\n Elements of the matrix \n : "); for(i=0;i<n;i++) { for(j=0;j<m;j++) printf("\t %d",a[i][j]); printf("\n"); } for(i=0;i<n;i++) { for(j=0;j<m;j++) { if(a[i][j]!=0) { s[k][l]=i; s[k][++l]=j; s[k][++l]=a[i][j]; k++; l=0; } } } printf("\n Elements of sparse matrix \n: "); for(i=0;i<k;i++) { for(j=0;j<3;j++) printf("\t %d",s[i][j]); printf("\n"); } getch(); } OUTPUT: Enter the no of rows: 2

Enter the no of columns: 2 Enter the elements in the array : 1 2 3 4 Elements of the matrix: 1 2 3 4 Elements of sparse matrix: 0 0 1 0 1 2 1 0 3 1 1 4 PROGRAM: f) Write a C program linked list #include<stdio.h> struct node { int row; int col; int data; struct node *link; }*head=NULL,*curr=NULL,*p=NULL; void main() { int i,j,m,n,a[50][50]; clrscr(); printf("\nSparse Matrix using Linked List\n"); printf("\nEnter the number of rows of the matrix:"); scanf("%d",&m); printf("Enter the number of columns of the matrix:"); scanf("%d",&n); printf("Enter the elements:");

to representation the given Sparse matrix using

for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&a[i][j]); if(a[i][j]!=0) { curr=(struct node*)malloc(sizeof(struct node)); curr->row=i; curr->col=j; curr->data=a[i][j]; curr->link=NULL; if(head==NULL) head=curr; else { p=head; while(p->link!=NULL) p=p->link; p->link=curr; } } } } printf("\nSparse matrix using linked list:\nRow\tColumn\tElement\t\n"); p=head; if(head==NULL)

printf("\nSparse matrix empty!\n"); else { while(p->link!=NULL) { printf("%d\t%d\t%d\n",p->row,p->col,p->data); p=p->link; } printf("%d\t%d\t%d\n",p->row,p->col,p->data); } getch(); } OUTPUT: Sparse Matrix using Linked List Enter the number of rows of the matrix:2 Enter the number of columns of the matrix: 2 Enter the elements:1 2 3 4 Sparse matrix using linked list: Row Column Element 0 0 1 0 1 2 1 0 3 1 1 4 Exercise10: a) Write a C program to Create a Binary Tree of integers b) Write a recursive C program, for Traversing a binary tree in preorder, inorder and postorder. c) Write a non recursive C program, for Traversing a binary tree in preorder, inorder and postorder. d) Program to check balance property of a tree.

PROGRAM: /* Operations on Binary tree */

#include <stdio.h> #include <conio.h> #include <process.h> struct tree { int info; struct tree *left; struct tree *right; }; typedef struct tree BT; BT* create(void); BT* insert(BT*, int); void preorder(BT *); void inorder(BT *); void postorder(BT *); int main(void) { BT *root=NULL; int ch; clrscr(); printf("\n ----------- OPERATIONS ON BINARY TREE-------------\n"); do { printf("\n 1. creation \n 2.preorder \n 3.inorder \n 4.postorder \n 5.quit\n"); printf("\n enter your choice\t"); scanf("%d",&ch); switch(ch) { case 1: root=create(); break; case 2: printf("\n preorder traversal of binary tree\n"); preorder(root); break; case 3: printf("\n inorder traversal of binary tree \n"); inorder(root); break; case 4: printf("\n postorder traversal of binary tree \n"); postorder(root); break; case 5: return(0); default: printf("\n invalid choice"); } }while(1); }

BT* create(void) { BT *root=NULL; char ch; int n; do { printf("\n enter integer to insert\t"); scanf("%d",&n); root=insert(root,n); printf("\n do u want to insert element [y/n]\t"); ch=getche(); }while(ch=='y' || ch=='Y'); return(root); } void preorder(BT *root) { if (root!=NULL) { printf("\t%d",root->info); preorder(root->left); preorder(root->right); } return; } void inorder(BT *root) { if(root !=NULL) { inorder(root->left); printf("\t%d",root->info); inorder(root->right); } return; } void postorder(BT *root) { if(root !=NULL) { postorder(root->left); postorder(root->right); printf("\t%d",root->info); } return; } BT* insert(BT *root,int n) {

BT *node; if (root== NULL) { node=(BT *)calloc(1,sizeof(BT)); if(node==NULL) { printf("\n unable to create node "); getch(); exit(1); } node->info=n; node->left = node->right = NULL; root=node; } else if(n < root->info) root->left=insert(root->left,n); else root->right=insert(root->right,n); return(root); } OUTPUT: ----------- OPERATIONS ON BINARY TREE------------1. creation 2.preorder 3.inorder 4.postorder 5.quit enter your choice 1 10 y y y y n

enter integer to insert

do u want to insert element [y/n] enter integer to insert 5 do u want to insert element [y/n] enter integer to insert 13 do u want to insert element [y/n] enter integer to insert 3 do u want to insert element [y/n] enter integer to insert 11 do u want to insert element [y/n] 1. creation

2.preorder 3.inorder 4.postorder 5.quit enter your choice 2

preorder traversal of binary tree 10 5 3 13 11 1. creation 2.preorder 3.inorder 4.postorder 5.quit enter your choice 3

inorder traversal of binary tree 3 5 10 11 13 1. creation 2.preorder 3.inorder 4.postorder 5.quit enter your choice 4 postorder traversal of binary tree 3 5 11 13 10 1. creation 2.preorder 3.inorder 4.postorder 5.quit enter your choice 5 Exercise 11: a) Write a C program to Create a BST b) Write a C program to insert a node into a BST. c) Write a C program to delete a node from a BST. PROGRAM: /*BINARY SEARCH TREE*/ #include<stdio.h> #include<conio.h> #include<alloc.h> struct node {

int data; struct node *left,*right; }*tree; void create(); void insert(); void del(); struct node *maketree(int); void display(struct node*); void setleft(struct node *,int); void setright(struct node *,int); void insert() { struct node *p,*q; int num; printf("\n\t\tEnter The Node Value : "); scanf("%d",&num); p=q=tree; while((num!=p->data)&&(q!=NULL)) { p=q; if(num<p->data) q=p->left; else q=p->right; } if(num==p->data) printf("\n\t\tDuplicate Value"); else if(num<p->data) setleft(p,num); else setright(p,num); } void main() { int ch; clrscr(); printf("\n\t\t\tBINARY SEARCH TREE"); printf("\n\t\t\t~~~~~~~~~~~~~~~~~~~~~"); printf("\n\t\t\t 1.CREATION"); printf("\n\t\t\t 2.INSERTION"); printf("\n\t\t\t 3.DELETION"); printf("\n\t\t\t 4.DISPLAY"); printf("\n\t\t\t 5.EXIT\n"); do { printf("\n\t\tEnter The Choice : "); scanf("%d",&ch); switch(ch) { case 1: create(); break;

case 2: insert(); break; case 3: if(tree==NULL) printf("\n\t Tree Empty"); else del(); break; case 4: printf("\n\t\tTREE CONTAINS : "); display(tree); printf("\n"); break; default:printf("\n\t\tEXIT"); } }while(ch<=4); getch(); } struct node *maketree(int val) { struct node *t=(struct node *)malloc(sizeof(struct node)); t->data=val; t->left=t->right=NULL; return(t); } void create() { int n,i,num; printf("\n\t\tEnter The No Of Node :"); scanf("%d",&n); printf("\n\t\tEnter The No Of Node :"); scanf("%d",&num); tree=maketree(num); for(i=2;i<=n;i++) insert(); } void display(struct node *p1) { if(p1==NULL) return; display(p1->left); printf("%d",p1->data); display(p1->right); } void setleft(struct node *p1,int val) { if(p1==NULL) printf("\n\t\tVoid Insertion"); else if(p1->left!=NULL) printf("\n\t\tInvalid Insertion"); else p1->left=maketree(val); }

void setright(struct node *p1,int val) { if(p1==NULL) printf("\n\t\tVoid Insertion"); else if(p1->right!=NULL) printf("\n\t\tInvalid Insertion"); else p1->right=maketree(val); } void del() { struct node *p,*q,*rp,*f,*s; int num; p=tree; q=NULL; printf("\n\t\tEnter The Node To Be Deleted : "); scanf("%d",&num); while((p!=NULL)&&(p->data!=num)) { q=p; p=(num<p->data)?p->left:p->right; } if(p==NULL) { printf("\n\t\tVoid Deletion"); return; } if(p->left==NULL) rp=p->right; else if(p->right==NULL) rp=p->left; else { f=p; rp=p->right; s=rp->left; while(s!=NULL) { f=rp; rp=s; s=rp->left; } if(f!=p) { f->left=rp->right; rp->right=p->right; } rp->left=p->left; } if(q==NULL)

tree=rp; else p=(q->left)?(q->left=rp):(q->right=rp); } OUTPUT: BINARY SEARCH TREE ~~~~~~~~~~~~~~~~~~~~~ 1.CREATION 2.INSERTION 3.DELETION 4.DISPLAY 5.EXIT Enter The Choice : 1 Enter The No Of Node :4 Enter The No Of Node :2 Enter The Node Value : 3 Enter The Node Value : 1 Enter The Node Value : 5 Enter The Choice : 4 TREE CONTAINS : 1235 Enter The Choice :5 EXIT Exercise 12: a) Write a C programme to compute the shortest path of a graph using Dijkstras algorithm b) Write a C programme to find the minimum spanning tree using Warshalls Algorithm PROGRAM: #include<stdio.h> #include<conio.h> #include<ctype.h> #define MAX 30 #define UNVISITED -1

#define VISITED 1 #define INFINITY 32767 int adjMat[MAX][MAX],n; void viewAdjMat(); void viewPathMat(int pm[MAX],int n,int len); int searchPath(int src,int des,int pathMat[MAX],int *minLen); typedef struct { int previous,len,status; }node; void main() { char ch,s,d; int i,j,k,src,des,minLen,tot,pathMat[MAX]; clrscr(); printf("\n DIJKSTRAS SHORTEST PATH ALGORITHM"); printf("\n\N Enter total number of vertex:"); scanf("%d",&n); printf("\n\n************ADJACENCY MATRIX********\n\n"); for(i=1;i<=n;i++) for(j=1;j<=n;j++) scanf("%d",&adjMat[i][j]); while(1) { printf("\n\n Enter the source node :"); fflush(stdin); scanf("%c",&s);

printf("\n\n Enter the destination node :"); fflush(stdin); scanf("%c",&d); src=toupper(s)-64; des=toupper(d)-64; tot=searchPath(src,des,pathMat,&minLen); viewPathMat(pathMat,tot,minLen); printf("\n Do you want to continue(y/n):"); ch=getche(); if(ch!='y' && ch!='Y') break;} } void viewPathMat(int pm[MAX],int n,int len) { int k; if(len!=0) { printf("\n Minimum length is:%d\n\n Shortest Path is:",len); for(k=n;k>1;k--) printf("%c-->",pm[k]+64);printf("%c\n",pm[k]+64); printf("\n Distance is : for(k=n;k>1;k--) { printf("%d } } else printf("\n NO path from source to destination node \n"); ",adjMat[pm[k]] [pm[k-1]]); ");

} int searchPath(int src,int des,int pathMat[MAX],int *minLen) { node graph[MAX]; int i,k,min,tot=0,curVertex,newLen,u,v; *minLen=0; for(i=1;i<=n;i++) { graph[i].previous=0;graph[i].len=INFINITY; graph[i].status=UNVISITED; } graph[src].previous=0;graph[src].len=0; graph[src].status=VISITED;curVertex=src; while(curVertex!=des){ for(k=1;k<=n;k++){ if(adjMat[curVertex][k]>0 && graph[k].status==UNVISITED){ newLen=graph[curVertex].len+adjMat[curVertex][k]; if(newLen<graph[k].len){ graph[k].previous=curVertex; graph[k].len=newLen; } } } min=INFINITY;curVertex=0; for(i=1;i<=n;i++) if(graph[i].status==UNVISITED && graph[i].len<min){ min=graph[i].len;curVertex=i;

} if(curVertex==0) return 0; graph[curVertex].status=VISITED; } while(curVertex!=0){ pathMat[++tot]=curVertex; curVertex=graph[curVertex].previous; } for(i=tot;i>1;i--){ u=pathMat[i];v=pathMat[i-1]; *minLen=*minLen+adjMat[u][v]; } return(tot); } OUTPUT: DIJKSTRAS SHORTEST PATH ALGORITHM Enter total number of vertex:2 ************ADJACENCY MATRIX******** 2 3 4 5 Enter the source node :2 Enter the destination node :3 NO path from source to destination node Do you want to continue(y/n): n

You might also like