Data Structure 18043
Data Structure 18043
Data Structure 18043
Practical no:-1
A. Write a program to store the elements in 1-D array and
perform the operations like searching, sorting, reversing the
elements.
Code:-
Searching the element:
#include<stdio.h
int main()
{
int a[100], n, element, pos=0;
int i;
printf("Enter array size : ");
scanf("%d", &n);
printf("Enter array elements: ");
for(i=0; i<n; i++)
scanf("%d", &a[i]);
printf("Enter element to search: ");
scanf("%d",&element);
for(i=0; i<n; i++)
{
if(a[i]==element)
{
printf("%d is found at position : %d", element, i+1);
return 0;
}
}
printf("%d not found.", element);
return 0;
}
output:
Sorting the element:
#include <stdio.h>
void main()
{
int i,j,n,a[100],temp,p,q,temp1;
printf("Enter the size of array : ") ;
scanf("%d",&n) ;
printf("Enter the elements : ") ;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]) ;
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++) { if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("\nAscending order of an array : \n");
for(i=0;i<n;i++)
{
printf("%d ",a[i]) ;
}
for(p=0;p<n;p++)
{
for(q=p+1;q<n;q++)
{
if(a[p]<a[q])
{
temp1=a[p];
a[p]=a[q];
a[q]=temp1;
}
}
}
printf("\n \nDescending order of an array : \n ");
for(p=0;p<n;p++)
{
printf("%d ",a[p]) ;
}
}
output:
Reversing the element:
#include <stdio.h>
int main()
{
int arr[100],reverse[100];
int size, i, a, b;
printf("Enter size of the array: ");
scanf("%d", &size);
printf("Enter elements in array: ");
for(i=0; i<size; i++)
{
scanf("%d", &arr[i]);
}
b = 0;
a = size - 1;
while(a >= 0)
{
reverse[b] = arr[a];
b++;
a--;
}
printf("\nReversed array : ");
for(i=0; i<size; i++)
{
printf("%d \t", reverse[i]);
}
return 0;
}
output:
B. Read the two arrays from the user and merge them and
display the elements in sorted order.
Code:-
#include <stdio.h>
int main()
{
int n1,n2,n3; //Array Size Declaration
printf("\nEnter the size of first array: ");
scanf("%d",&n1);
printf("\nEnter the size of second array: ");
scanf("%d",&n2);
n3=n1+n2;
printf("\nEnter the sorted array elements: ");
int a[n1],b[n2],c[n3]; //Array Declaration
for(int i=0;i<n1;i++) //Array Initialized
{
scanf("%d",&a[i]);
c[i]=a[i];
}
int k=n1;
printf("\nEnter the sorted array elements: ");
for(int i=0;i<n2;i++) //Array Initialized
{
scanf("%d",&b[i]);
c[k]=b[i];
k++;
}
printf("\nThe merged array..\n");
for(int i=0;i<n3;i++)
printf("%d ",c[i]); //Print the merged array
printf("\nAfter sorting...\n");
for(int i=0;i<n3;i++) //Sorting Array
{
int temp;
for(int j=i+1; j<n3 ;j++)
{
if(c[i]<c[j])
{
temp=c[i];
c[i]=c[j];
c[j]=temp;
}
}
}
for(int i=0 ; i<n3 ; i++) //Print the sorted Array
{
printf(" %d ",c[i]);
}
return 0;
}
output:
C. Write a program to perform the Matrix addition,
Multiplication, Transpose operation.
Code:-
#include<stdio.h>
#include<conio.h>
int main()
{
int
m,n,a[20][20],b[20][20],i,j,sum[20][20],sub[20][20],opt,tr[20][2
0]
,opt1,ch,e,f;
printf("Enter the no. of rows: ");
scanf("%d",&m);
printf("Enter the no. of columns: ");
scanf("%d",&n);
printf("Enter the Data Elements of first matrices\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
} printf("Enter the no. of rows for second matrices: ");
scanf("%d",&e);
printf("Enter the no. of columns: ");
scanf("%d",&f);
printf("Enter the Data Elements of second matrices\n");
for(i=0;i<e;i++)
{
for(j=0;j<f;j++)
{
scanf("%d",&b[i][j]);
}
}
do
{
if(m==e&&n==f)
{
int main()
{
int n, choice;
printf("Enter the total number of nodes: ");
scanf("%d", &n);
createList(n);
if(n <= 0)
{
printf("List size must be greater than zero.\n");
return;
}
head->data = data;
head->next = NULL;
temp = head;
for(i=2; i<=n; i++)
{
newNode = (struct node *)malloc(sizeof(struct node));
if(newNode == NULL)
{
printf("Unable to allocate memory.");
break;
}
else
{
printf("Enter the data of node %d: ", i);
scanf("%d", &data);
newNode->data = data;
newNode->next = NULL;
temp->next = newNode;
temp = temp->next;
}
}
if(head != NULL)
{
prevNode = head;
curNode = head->next;
head = head->next;
prevNode->next = NULL;
while(head != NULL)
{
head = head->next;
curNode->next = prevNode;
prevNode = curNode;
curNode = head;
}
head = prevNode;
void displayList()
{
struct node *temp;
if(head == NULL)
{
printf("List is empty.");
}
else
{
temp = head;
while(temp != NULL)
{
printf("Data = %d\n", temp->data);
temp = temp->next;
}
}
}
Output :
2(b).Write a program to search the elements in the
linked list and display the same
Code:-
#include <stdio.h>
#include <stdlib.h>
*, int);
void release(struct node **);
void display(struct node *);
int main()
{
struct node *p = NULL;
int key, result;
return 0;
}
return 0;
}
do
{
printf("Enter number: ");
scanf("%d", &c);
temp = (struct node *)malloc(sizeof(struct node));
temp->num = c;
temp->next = NULL;
if (*head == NULL)
{
*head = temp;
}
else
{
rear->next = temp;
}
rear = temp;
printf("Do you wish to continue [1/0]: ");
scanf("%d", &ch);
} while (ch != 0);
printf("\n");
}
Output:-
2(c).Write a program to create double linked
list and sort the elements in the linked list.
Code:-
#include <stdio.h>
#include <stdlib.h>
struct node {
int num;
struct node * preptr;
struct node * nextptr;
}*stnode, *ennode;
int main()
{
int n;
stnode = NULL;
ennode = NULL;
printf("\n\n Doubly Linked List : Create and display a
doubly linked list :\n");
printf("--------------------------------------------------------------
-----\n");
DlListcreation(n);
displayDlList();
return 0;
}
void DlListcreation(int n)
{
int i, num;
struct node *fnNode;
if(n >= 1)
{
stnode = (struct node *)malloc(sizeof(struct node));
if(stnode != NULL)
{
printf(" Input data for node 1 : ");
scanf("%d", &num);
stnode->num = num;
stnode->preptr = NULL;
stnode->nextptr = NULL;
ennode = stnode;
for(i=2; i<=n; i++)
{
fnNode = (struct node *)malloc(sizeof(struct
node));
if(fnNode != NULL)
{
printf(" Input data for node %d : ", i);
scanf("%d", &num);
fnNode->num = num;
fnNode->preptr = ennode;
fnNode->nextptr = NULL;
ennode->nextptr = fnNode;
ennode = fnNode;
}
else
{
printf(" Memory can not be allocated.");
break;
}
}
}
else
{
printf(" Memory can not be allocated.");
}
}
}
void displayDlList()
{
struct node * tmp;
int n = 1;
if(stnode == NULL)
{
printf(" No data found in the List yet.");
}
else
{
tmp = stnode;
printf("\n\n Data entered on the list are :\n");
while(tmp != NULL)
{
printf(" node %d : %d\n", n, tmp->num);
n++;
tmp = tmp->nextptr; // current pointer moves to
the next node
}
}
}
Output:
void push ()
{
int num;
if (s.top == (MAXSIZE - 1))
{
printf ("Stack is Full\n");
return;
}
else
{
printf ("\nEnter element to be pushed : ");
scanf ("%d", &num);
s.top = s.top + 1;
s.stk[s.top] = num;
}
return;
}
int pop ()
{
int num;
if (s.top == - 1)
{
printf ("Stack is Empty\n");
return (s.top);
}
else
{
num = s.stk[s.top];
printf ("poped element is = %d\n", s.stk[s.top]);
s.top = s.top - 1;
}
return(num);
}
void display ()
{
int i;
if (s.top == -1)
{
printf ("Stack is empty\n");
return;
}
else
{
printf ("\nStatus of elements in stack : \n");
for (i = s.top; i >= 0; i--)
{
printf ("%d\n", s.stk[i]);
}
}
}
int main ()
{
int ch;
s.top = -1;
Output:-
B. Write a program to convert an infix
expression to postfix and prefix conversion.
Input:-
#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;
}
#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;
Printf(“Enter the expression : “);
Scanf(“%s”,exp);
Printf(“\n”);
E = exp;
While(*e != ‘\0’)
{
If(isalnum(*e))
Printf(“%c “,*e);
Else if(*e == ‘(‘)
Push(*e);
Else if(*e == ‘)’)
{
While((x = pop()) != ‘(‘)
Printf(“%c “, x);
}
Else
{
While(priority(stack[top]) >= priority(*e))
Printf(“%c “,pop());
Push(*e);
}
E++;
}
While(top != -1)
{
Printf(“%c “,pop());
}return 0;
}
Output:-
C. Write a program to implement Tower of
Hanoi problem.
Input:-
#include<stdio.h>
void TOH(int n,char x,char y,char z)
{
if(n>0)
{
TOH(n-1,x,z,y);
printf("\n%c to %c",x,y);
TOH(n-1,z,y,x);
}
}
int main()
{
int n=3;
TOH(n,'A','B','C');
}
Output:-
Practical no:-4
(a). Write a program to implement the concept of Queue
with Insert, Delete, Display
and Exit operations.
Code:-
#include <stdio.h>
#define MAX 50
void insert();
void delete();
void display();
int queue_array[MAX];
int rear = - 1;
int front = - 1;
main()
{
int choice;
while (1)
{
printf("1.Insert element to queue \n");
printf("2.Delete element from queue \n");
printf("3.Display all elements of queue \n");
printf("4.Quit \n");
printf("Enter your choice : ");
scanf("%d", &choice);
switch (choice)
{
case 1:
insert();
break;
case 2:
delete();
break;
case 3:
display();
break;
case 4:
exit(1);
default:
printf("Wrong choice \n");
}
}
}
void insert()
{
int add_item;
if (rear == MAX - 1)
printf("Queue Overflow \n");
else
{
if (front == - 1)
/*If queue is initially empty */
front = 0;
printf("Inset the element in queue : ");
scanf("%d", &add_item);
rear = rear + 1;
queue_array[rear] = add_item;
}
}
void delete()
{
if (front == - 1 || front > rear)
{
printf("Queue Underflow \n");
return ;
}
else
{
printf("Element deleted from queue is : %d\n",
queue_array[front]);
front = front + 1;
}
}
void display()
int i;
if (front == - 1)
else
printf("Queue is : \n");
Output:-
#include <stdio.h>
#define SIZE 5
int items[SIZE];
int front = -1, rear = -1;
// Removing an element
int deQueue() {
int element;
if (isEmpty()) {
printf("\n Queue is empty !! \n");
return (-1);
} else {
element = items[front];
if (front == rear) {
front = -1;
rear = -1;
}
// Q has only one element, so we reset the
// queue after dequeing it. ?
else {
front = (front + 1) % SIZE;
}
printf("\n Deleted element -> %d \n", element);
return (element);
}
}
// Display the queue
void display() {
int i;
if (isEmpty())
printf(" \n Empty Queue\n");
else {
printf("\n Front -> %d ", front);
printf("\n Items -> ");
for (i = front; i != rear; i = (i + 1) % SIZE) {
printf("%d ", items[i]);
}
printf("%d ", items[i]);
printf("\n Rear -> %d \n", rear);
}
}
int main() {
// Fails because front = -1
deQueue();
enQueue(1);
enQueue(2);
enQueue(3);
enQueue(4);
enQueue(5);
display();
deQueue();
display();
enQueue(7);
display();
return 0;
}
Output:-
(c). Write a program to implement the concept
of Deque.
Code:-
#include <stdio.h>
#define MAX 10
void addFront(int *, int, int *, int *);
void addRear(int *, int, int *, int *);
int delFront(int *, int *, int *);
int delRear(int *, int *, int *);
void display(int *);
int count(int *);
int main() {
int arr[MAX];
int front, rear, i, n;
if (*pfront == -1) {
*pfront = *prear = 0;
arr[*pfront] = item;
return;
}
if (*prear != MAX - 1) {
c = count(arr);
k = *prear + 1;
for (i = 1; i <= c; i++) {
arr[k] = arr[k - 1];
k--;
}
arr[k] = item;
*pfront = k;
(*prear)++;
} else {
(*pfront)--;
arr[*pfront] = item;
}
}
if (*pfront == -1) {
*prear = *pfront = 0;
arr[*prear] = item;
return;
}
if (*prear == MAX - 1) {
k = *pfront - 1;
for (i = *pfront - 1; i < *prear; i++) {
k = i;
if (k == MAX - 1)
arr[k] = 0;
else
arr[k] = arr[i + 1];
}
(*prear)--;
(*pfront)--;
}
(*prear)++;
arr[*prear] = item;
}
if (*pfront == -1) {
printf("\nDeque is empty.\n");
return 0;
}
item = arr[*pfront];
arr[*pfront] = 0;
if (*pfront == *prear)
*pfront = *prear = -1;
else
(*pfront)++;
return item;
}
if (*pfront == -1) {
printf("\nDeque is empty.\n");
return 0;
}
item = arr[*prear];
arr[*prear] = 0;
(*prear)--;
if (*prear == -1)
*pfront = -1;
return item;
}
Output:-
Practical no:- 5. Implement the following sorting techniques:
5a)
Code:-
#include <stdio.h> void
bubblesort(int arr[], int size)
{ int
i, j;
{
int temp;
temp = *a;
*a = *b;
*b = temp;
int main()
Output:
5b)
Aim:- Write a program to implement selection sort.
Code:- #include
<stdio.h>
int i, j, min_idx;
min_idx = i; for (j =
i+1; j < n; j++) if (arr[j] <
arr[min_idx]) min_idx
= j;
// Swap the found minimum element with the first element swap(&arr[min_idx],
&arr[i]);
}
}
/* Function to print an array */ void
printArray(int arr[], int size)
{
int i;
for (i=0; i < size; i++)
printf("%d ", arr[i]); printf("\n");
}
Output:
5c)
Code:- #include
<math.h>
#include <stdio.h>
j = j - 1;
arr[j + 1] = key;
insertionSort(arr, n);
printArray(arr, n);
return 0;
Output:
6a)
Aim:- Write a program to implement merge sort.
Code:-
#include <stdio.h>
#include <stdlib.h>
k++;
{ if (l <
r) {
// Same as (l+r)/2, but avoids overflow for
// large l and h
int m = l + (r - l) / 2;
merge(arr, l, m, r);
/* UTILITY FUNCTIONS */ /*
Function to print an array */
void printArray(int A[], int size)
{
int i;
for (i = 0; i < size; i++)
printf("%d ", A[i]); printf("\n");
}
/* Driver code */
int main()
{
Output:
6b)
Code:-
#include <stdio.h>
#define MAX 5
int i,pos=-1;
if(a[i]==n)
pos=i;
break;
return pos;
int main()
position=linearSearch(arr,num);
if(num==-1) printf("Element
not found.\n");
else
return 0;
Output:
6c)
Code:-
#include <stdio.h> void
binary_search();
void binary_search()
beg = 0;
beg = mid + 1;
mid = (beg + end) / 2;
}
Output:
75 | P a g e
TreeDepth(tree,&depth,0);
printf("\nTree Depth =%d\n",depth);
}
return(0);
}
TREE *InsertTree(int data,TREE *p) {
if(!p) {
p=(TREE*)malloc(sizeof(TREE));
p->data=data;
p->left=NULL;
p->right=NULL;
return(p);
}
if(data < p->data)
p->left=InsertTree(data,p->left); else
if(data > p->data)
p->right=InsertTree(data,p->right);
return(p);
}
TREE *PrintTreeTriangle(TREE *tree, int level) {
int i;
if(tree) {
PrintTreeTriangle(tree->right,level+1);
printf("\n\n");
for (i=0;i<level;i++)
printf(" ");
printf("%d",tree->data);
PrintTreeTriangle(tree->left,level+1);
}
return(NULL);
76 | P a g e
}
int TreeDepth(TREE *tree,int *depth,int level) {
if(tree) {
if (level>*depth)
*depth=level;
TreeDepth(tree->left,depth,level+1);
TreeDepth(tree->right,depth,level+1);
}
return(0);
}
Output:
Practical 7b)
struct treenode
{
int info;
struct treenode *lchild;
struct treenode *rchild;
}*root=NULL;
struct listnode
{
struct listnode *prev;
int info;
struct listnode *next;
}*pre=NULL, *in=NULL;
int main( )
{
int n;
printf("\nEnter inorder\n");
in = create_list(in, n);
printf("\nEnter preorder\n");
pre=create_list(pre, n);
root = construct(in,pre,n);
printf("\nInorder : "); inorder(root);
printf("\n\nPostorder : "); postorder(root);
printf("\n\nPreorder : "); preorder(root);
printf("\n\n\nTree is : \n");
display(root,0);
printf("\n");
return 0;
}
int i,j;
if(num==0)
return NULL;
q = inptr;
for(i=0; q->info != preptr->info; i++)
q = q->next;
return temp;
}/*End of construct()*/
#include <iostream>
struct Node {
int data;
struct Node *left, *right;
Node(int data)
this->data = data;
};
if (node == NULL)
return;
printPostorder(node->left);
printPostorder(node->right);
if (node == NULL)
return;
printInorder(node->left);
printInorder(node->right);
{
if (node == NULL)
return;
printPreorder(node->left);
printPreorder(node->right);
int main()
printPreorder(root);
printInorder(root);
printPostorder(root);
return 0;
Output:
Practical no 8
Aim:- Write a program to insert the element into minimum heap.
Code:
#include <iostream>
#include <conio.h>
int j, t;
t= a[m];
j = 2 * m;
while (j <= n) {
j = j + 1;
if (t < a[j])
break;
a[j/2] = a[j];
j = 2 * j;
a[j/2] = t;
return;
}
void build_minheap(int *a, int n) {
int k;
min_heap(a,k,n);
int main() {
int n, i;
cin>>n;
int a[30];
cin>>a[i];
build_minheap(a, n);
cout<<"Min Heap\n";
cout<<a[i]<<endl;
getch();
Output
enter no of elements of array
5
enter element 1
7
enter element 2
6
enter element 3
2
enter element 4
1
enter element 5
4
Min Heap
1
4
2
6
7
Practical no.8(b)
#include <conio.h>
int j, t;
t= a[m];
j = 2 * m;
while (j <= n) {
if (t < a[j])
break;
a[j/2] = a[j];
j = 2 * j;
a[j/2] = t;
return;
int k;
min_heap(a,k,n);
int main() {
int n, i;
cin>>n;
int a[30];
cin>>a[i];
}
build_minheap(a, n);
cout<<"Min Heap\n";
cout<<a[i]<<endl;
getch();
Output
enter no of elements of array
5
enter element 1
7
enter element 2
6
enter element 3
2
enter element 4
1
enter element 5
4
Min Heap
1
4
2
6
7
Practical no.9(a)
Aim: Write a program to implement the collision technique.
Code:
#include<bits/stdc++.h>
class Hash
list<int> *table;
public:
int hashFunction(int x) {
return (x % BUCKET);
}
void displayHash();
};
Hash::Hash(int b)
this->BUCKET = b;
table[index].push_back(key);
for (i = table[index].begin();
i != table[index].end(); i++) {
if (*i == key)
break;
if (i != table[index].end())
table[index].erase(i);
void Hash::displayHash() {
cout << i;
// Driver program
int main()
int n = sizeof(a)/sizeof(a[0]);
// insert the keys into the hash table
// hash table
h.insertItem(a[i]);
h.deleteItem(12);
h.displayHash();
return 0;
Output:
0
1 --> 15 --> 8
4 --> 11
6 --> 27
1 --> 15 --> 8
Practical no.9(b)
Code:
#include <stdio.h>
#include<stdlib.h>
#define TABLE_SIZE 10
int h[TABLE_SIZE]={NULL};
void insert()
{
int key,index,i,flag=0,hkey;
printf("\nenter a value to insert into hash table\n");
scanf("%d",&key);
hkey=key%TABLE_SIZE;
for(i=0;i<TABLE_SIZE;i++)
{
index=(hkey+i)%TABLE_SIZE;
if(h[index] == NULL)
{
h[index]=key;
break;
}
if(i == TABLE_SIZE)
int key,index,i,flag=0,hkey;
printf("\nenter search element\n");
scanf("%d",&key);
hkey=key%TABLE_SIZE;
for(i=0;i<TABLE_SIZE; i++)
{
index=(hkey+i)%TABLE_SIZE;
if(h[index]==key)
{
printf("value is found at index %d",index);
break;
}
}
if(i == TABLE_SIZE)
printf("\n value is not found\n");
}
void display()
{
int i;
}
main()
{
int opt,i;
while(1)
{
printf("\nPress 1. Insert\t 2. Display \t3. Search \t4.Exit \n");
scanf("%d",&opt);
switch(opt)
{
case 1:
insert();
break;
case 2:
display();
break;
case 3:
search();
break;
case 4:exit(0);
}
}
}
Output
at index 0 value = 0
at index 1 value = 0
at index 2 value = 12
at index 3 value = 13
at index 4 value = 22
at index 5 value = 0
at index 6 value = 0
at index 7 value = 0
at index 8 value = 0
at index 9 value = 0
Press 1. Insert 2. Display 3. Search 4.Exit
3
enter search element
12
value is found at index 2
Press 1. Insert 2. Display 3. Search 4.Exit
23
Practical no.10(a)
Aim: Implement the following data structure techniques: a. Write a program to generate the adjacency
matrix.
Code:
#include<stdio.h>
int main()
int max_edges,i,j,origin,destin;
int graph_type;
scanf("%d",&graph_type);
scanf("%d",&n);
if(graph_type==1)
max_edges = n*(n-1)/2;
else
max_edges = n*(n-1);
scanf("%d %d",&origin,&destin);
break;
printf("\nInvalid vertex!\n");
i--;
}
else
adj[origin][destin] = 1;
adj[destin][origin] = 1;
}/*End of for*/
printf("%4d",adj[i][j]);
printf("\n");
}/*End of main()*/
OUTPUT : :
0 1 1 1 0
0 0 0 1 0
0 0 0 1 0
0 0 0 0 1
0 0 1 0 0
Process returned 0
Practical no.10(b)
Code:
#include <limits.h>
#include <stdio.h>
#define V 9
return min_index;
int dist[V];
bool sptSet[V];
dist[src] = 0;
sptSet[u] = true;
if (!sptSet[v] && graph[u][v] && dist[u] != INT_MAX && dist[u] + graph[u][v] < dist[v]) dist[v] =
dist[u] + graph[u][v];
printSolution(dist, V);
int main() {
int graph[V][V] = { { 0, 6, 0, 0, 0, 0, 0, 8, 0 },
{ 6, 0, 8, 0, 0, 0, 0, 13, 0 },
{ 0, 8, 0, 7, 0, 6, 0, 0, 2 },
{ 0, 0, 7, 0, 9, 14, 0, 0, 0 },
{ 0, 0, 0, 9, 0, 10, 0, 0, 0 },
{ 0, 0, 6, 14, 10, 0, 2, 0, 0 },
{ 0, 0, 0, 0, 0, 2, 0, 1, 6 },
{ 8, 13, 0, 0, 0, 0, 1, 0, 7 },
{ 0, 0, 2, 0, 0, 0, 6, 7, 0 }
};
dijkstra(graph, 0);
return 0;
}
Output
Vertex Distance from Source
0 0
1 6
2 14
3 21
4 21
5 11
6 9
7 8
8 15
Rollno:18043
3
4 --> 11
5
6 --> 27