Data Structure Lab Record
Data Structure Lab Record
Code:
#include <stdio.h>
#define MAX 10
void main()
{
int a[MAX][MAX],b[MAX][MA X],c[MA X][MA X],i,j,k,m,n,p,q;
clrscr();
printf("Enter the order of the first matrix\n");
scanf("%d %d",&m,&n);
printf("Enter the order of the second matrix\n");
scanf("%d %d",&p,&q);
if(n!=p)
{
printf("The matrix can not be multiplied\n");
}
else
{
printf("Enter the elements of the first matrix\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("Enter the elements of the second matrix\n");
for(i=0;i<p;i++)
for(j=0;j<q;j++)
scanf("%d",&b[i][j]);
for(i=0;i<m;i++)
for(j=0;j<q;j++)
{
c[i][j]=0;
for(k=0;k<n;k++)
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
}
printf("The resultant matrix on multiplication is\n");
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
printf("%d\t",c[i][j]);
printf("\n");
}
}
getch();
}
Output:
Enter the order of the first matrix
23
Enter the order of the second matrix
32
Enter the elements of the first matrix
12
34
56
Enter the elements of the second matrix
123
456
The resultant matrix on multiplication is
22 28
49 64
Ex 2: Write a program in `C Language to accept 10 strings as input and print them in lexicographic order.
Code:
#include <stdio.h>
void main()
{
char str[10][10],t[10];
int i,j;
clrscr();
for(i=0;i<10;++i)
strcpy(str[i],"");
printf("Enter the strings -\n");
for(i=0;i<10;++i)
scanf("%s",str[i]);
for(i=0;i<10;++i)
{
for(j=i+1;j<10;++j)
if(strcmp(str[i],str[j])>0)
{
strcpy(t,str[i]);
strcpy(str[i],str[j]);
strcpy(str[j],t);
}}
printf("The strings in lexicographical order is -\n");
for(i=0;i<10;++i)
printf("%s\n",str[i]);
getch();
}
Output:
Enter 10 strings Irshad Amol Abhay Pranay Anant Mangesh Vishal Alok Vivek Sameer
Strings in lexicographic orderAbhay Amol Anant Alok Irshad Mangesh Pranay Sameer Vishal Vivek
Code:
#include
#include<string.h>
void main()
{
int i=0,j=0,v,c=0,l1,l2;
char s1[50],s2[50];
clrscr();
printf("Enter 2 strings\n");
gets(s1);
gets(s2);
l1=strlen(s1);
l2=strlen(s2);
while(i<=l1)
{
if(j==l2)
{
v=i-l2+1;
c++;
printf("Start of %d occurance=%d end =%d\n",c,v,i);
j=0;
}
else if(s1[i]==s2[j])
{
i++;
j++;
}
else
{
i++;
j=0;
}
}
if(c==0)
printf("Not substring");
getch();
}
Output:
Enter 2 strings welcome to alfec welcome to all
welcome
Start of 1 occurance=1 end =7 Start of 2 occurance=18 end =24
Output:
Enter first string : Welcome
Enter second String: to Alfec
concatenated string : Welcome to Alfec
Session 2 : Structures
Ex 5: Write a program in C language, which accepts Enrolment number, Name Aggregate marks secured
in a Program by a student. Assign ranks to students according to the marks secured. Rank-1 should be
awarded to the students who secured the highest marks and so on. The program should print the enrolment
number, name of the student and the rank secured in ascending order.
Code:
#include<stdio.h>
#include<conio.h>
struct stud
{
int roll;
int mark;
char name[15];
};
main()
{
struct stud S[10], t;
int i, j, n;
clrscr();
printf("Enter numbers of students\n");
scanf("%d",&n);
for(i=0;i<n;++i)
{
printf("Enter roll no., name, mark\n");
scanf("%d %s %d",&S[i].roll,&S[i].name,&S[i].mark);
}
for(i=0;i<n;i++)
for(j=i+1;j<3;++j)
if(S[i].mark<S[j].mark)
{
if(S[i].mark<S[j].mark)
{
t=S[i];
S[i]=S[j];
S[j]=t;
}
printf("\nRank List\n\n");
printf("Roll No Name Mark Rank\n");
for(i=0;i<n;++i)
{
printf("%d\t%s\t\t%d\t%d\n",S[i].roll,S[i].name,S[i].mark,i+1);
}
}
getch();
}
Output:
Enter numbers of students
3
Enter roll no., name, mark
1
VINU
50
Enter roll no., name, mark
2
GEETHA
60
Enter roll no., name, mark
3
RAMU
55
Rank List
Roll No
Name
Mark
2
GEETHA
60
1
VINU
50
3
RAMU
55
Rank
1
2
3
struct sp
{
int row,col;
int mat[10][10];
int sp[50][3];
};
/* to convert the entered matrix to sparce form,by eleminating zero values*/
int convsp(struct sp *M )
{
int e=1,i,j;
printf("enter number of rows and columns in the matrix");
scanf("%d%d",&M->row,&M->col);
printf("enter the matrix");
for(i=0;i<M->row;++i)
for(j=0;j<M->col;++j)
{scanf("%d",&M->mat[i][j]);
if(M->mat[i][j]!=0)
{
M->sp[e][0]=i;
M->sp[e][1]=j;
M->sp[e][2]=M->mat[i][j];
e++;
}//end if
}/*end j loop*/
M->sp[0][0]=M->row; //store number of rows to first(row,col) of sparse
M->sp[0][1]=M->col; //store number of cols to first row,second col
M->sp[0][2]=e-1; //store total number of non zero values to 3rd column
return M->sp[0][2]; //return total number of non zero elements
}
/*to multiply the 2 matrix**/
mult(struct sp M1,int e1, struct sp M2,int e2)
{
int sum[10][10],i,j,k1,k2;
for(i=0;i<10;++i)
for(j=0;j<10;++j)
sum[i][j]=0;
for(i=1;i<=e1;++i)
for(j=1;j<=e2;++j)
if(M1.sp[i][1]==M2.sp[j][0])
{
k1=M1.sp[i][0]; k2=M2.sp[j][1];
sum[k1][k2]+=M1.sp[i][2]*M2.sp[j][2];
}
printf("\nproduct matrix\n");
for(i=0;i<M1.row;++i)
{
for(j=0;j<M2.col;++j)
printf("%d\t",sum[i][j]);
printf("\n");
}
}
/*to print sparse matrix ***/
void printsp(int n,struct sp matx)
{
int i,j;
for(i=0;i<=n;++i)
{
for(j=0;j<3;++j)
printf("%d\t",matx.sp[i][j]);
printf("\n");
}}
main()
{
int ele1,ele2;
struct sp m1,m2;
clrscr();
ele1=convsp(&m1);
Output:
Enter number of rows and columns in the matrix
33
Enter the matrix
100
010
111
SPARSE MATRIX1
335
001
111
201
211
221
Enter number of rows and columns in the matrix
33
Enter the matrix
010
100
101
SPARSE MATRIX2
334
011
101
201
221
Product matrix
010
100
211
Ex 7: Write a program in C language to accept a paragraph of text as input. Make a list of words and the
number of occurrences of each word in the paragraph as output. As part of the processing, an array and
structure should be created wherein each structure consists of two fields, namely, one for storing the word
and the other for storing the number of occurrences of that word.
Code:
#include<stdio.h>
#include<conio.h>
struct paragraph
{
char words[15];
int occ;
}p[50];
void main()
{
int i=0,j=0,k=0,flag=0;
char w[15],ch=0;
clrscr();
strcpy(w," ");
printf("Enter the paragraph\n");
while(ch!='\n')
{
flag=0;
strcpy(p[j].words,"");
p[j].occ=1;
ch=getchar();
w[i]=ch;
i++;
if(ch==' ')
{
w[i]='\0';
for(k=0;k<=j;++k)
if(strcmp(p[k].words,w)==0)
{
p[k].occ++;
flag=1;
}
if(flag==0)
{
strcpy(p[j].words,w);
++j;
}
strcpy(w," ");
i=0;
}
}
printf("words\t\toccurance\n");
for(i=0;i<j;i++)
printf("%s\t\t%d\n",p[i].words,p[i].occ);
getch();
}
Output:
Enter a paragraph
May God bless you children be good children
Word Occurrence
May 1
God 1
bless 1
you 1
children 2
good 1
be 1
Code:
/*Creation and deletion of linked list*/
#define NULL 0
struct student
{
char name[15];
int roll_no;
struct student *next;
}*stud,*first;
/*creation of list*/
list_create(struct student *s1)
{
printf("Enter roll number:-1 to terminate\n");
scanf("%d",&s1->roll_no);
if(s1->roll_no!=-1)
{
printf("Enter name: ");
scanf("%s",s1->name);
s1->next=(struct student*)malloc(sizeof(struct student));
list_create(s1->next);
}
else
{
s1->next=NULL;
return;
}
}
/*Display the list */
display_list(struct student *s1)
{
if(first->next==NULL)
{
printf("List is empty");
getch();
return 0;
}
while(s1->next)
{
printf("%d\t%s\n",s1->roll_no,s1->name);
s1=s1->next;
}
getch();
return 0;
}
/*Delete from list */
delete_element(struct student *start)
{
struct student *temp,*t;
int roll,flag=0;
if(first->next==NULL)
{
printf("List empty");
getch();
return 0;
}
printf("Enter rollnumber to delete\n");
scanf("%d",&roll);
if(start->roll_no==roll)
{
temp=start->next;
free(start);
first=temp;
return 0;
}
/* any other node */
t=start;/*store previous node t*/
start=start->next; /*point next node */
while(start)
{
if(start->roll_no==roll)
{
temp=start->next;
free(start);
t->next=temp;
return;
}
t=t->next;
start=start->next;
flag=1;
}
if(flag==1)
{
printf("Rollnumber not found");
getch();
return(0);
}
}
main()
{
int choice=0;
clrscr();
stud=(struct student*)malloc(sizeof(struct student));
first=stud;
first->next=NULL;
while(choice!=4)
{
clrscr();
printf("MENU\n\n");
printf("Create....1\n\nDisplay...2\n\nDelete...3\n\nExit...4\n\n");
printf("Enter choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
list_create(stud);
break;
case 2:
display_list(stud);
break;
case 3:
delete_element(stud);
break;
case 4: break;
}
}
getch();
return 0;
}
Output:
MENU
67. create
68. display
69. delete
70. Exit
Enter choice : 1
Enter roll number : 12
Enter name : Anu
Enter roll number : -1
return to main menu
Ex 9: Write a program in C language that accepts two singly linked lists A and B as input. Now, print a
singly linked list that consists of only those elements, which are common to both A and B.
Code:
# include<stdio.h>
# include<conio.h>
struct student
{
int roll no; struct student *next;} *s1, *s2;
/*creation of linked list*/
List-create (struct student *S1)
{
print f (enter roll number) ; Scan f(%d, & s1roll no.);
if (s1roll no 1= -1) /* -1 is entered to stop*/
{
sinext (struct student*) malloc (size of (struct students));
list-create (s1next);
}
else s1next = NULL
return
}
Output:
enter roll number : 12
enter roll number : 13
enter roll number : 14
enter roll number : -1
elements in the first list :
12 13 14
enter
enter
enter
enter
enter
enter
Ex 10: Write a program in C language to accept a singly linked list of integers as input. Now, sort the
elements of the list in ascending order. Then, accept an integer as input. Insert this integer into the singly
linked list at the appropriate position.
Code:
/* to sort a linked list and insert an element at the proper position*/
#include<stdio.h>
#include<conio.h>
struct student
{
int rollno;
struct student *next;
}*stud,*first;
/*******creation of list********/
void list_create(struct student *s1)
{
clrscr();
printf("enter roll number-1 to stop"); scanf("%d",&s1->rollno);
if(s1->rollno!=-1)
{
// printf("enter name"); scanf("%s",s1->name);
s1->next=(struct student*)malloc(sizeof(struct student));
list_create(s1->next);
}
else s1->next=NULL;
return;
}
/*****display the list **********/
void display_list(struct student *s1)
{
if(s1->next!=NULL)
{
printf("%d\n",s1->rollno);
// printf("%d\t%s",s1->next->rollno,s1->next->name);
// printf("%d\t%s",s1->next->nextrollno,s1->next->next->name);
display_list(s1->next);
}
}
/********sort list ***********/
void sort_list(struct student *s1)
{
struct student *temp,*t,*t1;
if(s1->next==NULL)
return;
t=s1;
while(t)
{
t1=t->next;
while(t1->next!=NULL)
{if(t->rollno>t1->rollno)
{temp->rollno=t->rollno;
t->rollno=t1->rollno;
t1->rollno=temp->rollno;
}t1=t1->next;}
t=t->next;}
}
/**inserting an element to list*/
insert_element(struct student *s1)
{ int r; struct student* temp,*prev;
printf("enter rollnumber to insert"); scanf("%d",&r);
//to insert before the first node
if(r<s1->rollno)
{ temp=(struct student*)malloc(sizeof(struct student));
temp->rollno=r;
temp->next=s1;
first=temp; return;
}
/*to insert in between any node*/
while(s1->next)
{
if(s1->rollno <r){prev=s1;
s1=s1->next;}
else
{temp=(struct student*)malloc(sizeof(struct student));
temp->rollno=r;
temp->next=prev->next;
prev->next=temp;
break;}
}
/*to insert after last node*/
if(s1->next==NULL && r>s1->rollno)
{
temp=(struct student*)malloc(sizeof(struct student));
temp->rollno=r;
temp->next=prev->next;
prev->next=temp;
}}
/********searching for an element in the list ********/
/*struct student* search(struct student *start, int rn)
{
if(start->next==NULL)
return (NULL);
if(start->next->rollno==rn)
return(start);
else
search(start->next,rn);
return NULL;
}*/
/********* delete element from list *************/
/*struct student* delete_element(struct student *start)
{
struct student *temp,*t; int roll;
printf("enter rollnumber to delete"); scanf("%d",&roll);
if(start->rollno==roll)
{
temp=start->next;
free(start);
start=temp;
}
else
{
t=search(start,roll);
if(t==NULL)
printf("roll number not found\n");
else
{ temp=t->next->next; free(t->next); t->next=temp; }
}return(start);
}*/
/*********main ***********/
main()
{
clrscr();
first=(struct student*)malloc(sizeof(struct student));
stud=(struct student*)malloc(sizeof(struct student));
first=stud;// first->next=NULL;
list_create(stud);
display_list(stud);
//stud=delete_element(stud);
printf("\nsorted list\n");
sort_list(stud);
display_list(stud);
insert_element(stud);
display_list(first);
getch();
return;
}
Output:
Enter roll number-1 to stop
10 68 74 1 22 99 4 3
Sorted list 1 3 4 10 22 68 74 99
Enter rollnumber to insert
15 1 3 4 10
Session 4 : Stacks
Ex 12: Write a program in C language to reverse an input string.
Code:
/* to reverse a string using stack */
#include<stdio.h>
#include<conio.h>
struct list
{
char ch;
struct list *next;
}*top=NULL;
/*store string to stak*/
push(char s)
{
struct list* t;
t=(struct list*)malloc(sizeof(struct list));
t->ch=s;
t->next=top;
top=t;
}
/*display reverse string*/
display()
{
struct list *tmp;
tmp=top;
while(tmp!=NULL){
printf("%c",tmp->ch);
tmp=tmp->next;
}
}
main()
{
char c;
clrscr();
printf("enter a string\n");
while(c!='\n')
{
c=getchar();
push(c); }
printf("reversed string is\n");
display();
getch();
}
Output:
Enter a string : IGNOU
Reversed string is - UONGI
else
{
printf("%d\n",a[t1]);
t1--;
}
break;
case 2:
if(t2<=10)
printf("stack 2:empty\n");
else
{
printf("%d\n",a[t2]);
t2--;
}
break;
}
}
Output:
1. push
2. pop
3. exit
enter your choice :1
enter stuck no.1
enter value 10
1. push
2. pop
3. exit
enter your choice :1 enter stuck no.1
enter value: 11
enter choice : 1 enter stuck no.2
enter value : 21
enter choice : 1, enter stuck no.2
enter value : 22
enter choice :2 enter stuck no.1
value = 11
enter choice : 2 ENTER STUCK NO.2
value = 22
enter choice : 3
exit the program
Session 5 : Queues
Ex 15: Write a program in C language to implement a Dequeue using pointers. All operations associated
with a Dequeue are to be implemented.
Code:
/*to implemnet a dequ using linked list using pointer **/
#include<stdio.h>
#include<conio.h>
struct node
{
int data;
struct node *link;};
void addqatend(struct node**,struct node**,int);
void addqatbeg(struct node**,struct node**,int);
delqatbeg(struct node**,struct node**);
delqatend(struct node**,struct node**);
main()
{
struct node*front,*rear;
int item;
front=rear=NULL;
addqatend(&front,&rear, 11);
addqatend(&front,&rear, 81);
addqatend(&front,&rear, 16);
addqatend(&front,&rear, 45);
clrscr();
q_display(front);
printf("\nnumber of elements in the que=%d",count(front));
printf("\nitems taken from q\n");
item=delqatbeg(&front,&rear);
printf("%d ",item);
printf("\nafter deletion\n");
q_display(front);
getch();
}
/*adds a new element at end **/
void addqatend(struct node **f,struct node **r,int item)
{
struct node *q;
q=(struct node*)malloc(sizeof(struct node));
q->data=item;
q->link=NULL;
/**if q empty**/
if(*f==NULL)
*f=q;
else
(*r)->link=q;
*r=q;
}
/*add at begin**/
void addqatbeg(struct node** f,struct node** r,int item)
{
struct node *q;
int t;
q=(struct node*)malloc(sizeof(struct node));
q->data=item;
q->link=NULL;
/**if q empty**/
if(*f==NULL)
*f=*r=q;
else
q->link=*f;
*r=*f;
*f=q;
}
/*remove from front ***/
delqatbeg(struct node** f,struct node** r)
{
struct node *q; int item;
if(*f==NULL)
printf("q empty");
else
q=*f;item=q->data;
*f=q->link; free(q);
/*if q becom empty after delet*/
if(*f==NULL)
*r=NULL;
return item;
}
/*remove from rear end ***/
delqatend(struct node** f,struct node** r)
{
struct node *q,*rleft,*temp; int item;
temp=*f;
if(*r==NULL)
printf("q empty");
else
/*traverse q to find the prevous element adrs*/
while(temp!=*r)
{rleft=temp; temp=temp->link;}
Output:
front->11 81 16 <-rear45
number of elements in the que=4
item taken from q
11
after deletion
front->81 16 <-rear45
clrscr();
add();
display();
getch();
}
Output:
Enter numbers(5 only)
num=1
num=2
num=3
num=4
num=5
The numbers in reverse order are:
5
4
3
2
1
del();
printf("\nElements after deleting second ele\n");
display();
getch();
}
Output:
Enter 10 numbers to the stuk
1 2 3 4 5 6 7 8 9 0
Elements in the que:
1 2 3 4 5 6 7 8 9 0
Elements in the que after deleting first element
2 3 4 5 6 7 8 9 0
Elements after deleting 2nd element
3 4 5 6 7 8 0
Output:
How many elements you want to enter in the array : 5
Enter element 1 : 45
Enter element 2 : 98
Enter element 3 : 75
Enter element 4 : 86
Enter element 5 : 42
Enter the element to be searched : 75
75 found at position 3
int arr[]={0,1,2,3,4,5,7,12,53,31,78,87,65,45,100,200};
int i,j,n=15,temp,num,pos;
char ans;
clrscr();
printf("Do u want to enter values to array automaticaly y/n:");
scanf("%c",&ans);
if(ans=='n')
{
printf("Enter number of elts, max is 15 :");
scanf("%d",&n);
printf("Enter %d elements...\n",n);
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
}
for(i=0;i<n-1;i++)
for(j=i;j<n;j++)
if(arr[i]< arr[j])
{
temp=arr[j];
arr[j]=arr[i];
arr[i]=temp;
}
printf("\nEntered array after sorting is...\n");
for(i=0;i<n;i++)
{
printf("%d ",arr[i]);
}
sear: printf("\nEnter the number to be searched:");
scanf("%d",&num);
if(search(arr,0,n-1,num,&pos))
printf("Entered number %d found at position %d\n",num,pos+1);
else
printf("Entered number %d not found \n",num);
printf("\Search again y/n :");
scanf(" %c",&ans);
if(ans=='y')goto sear ;
}
int search(int *arr,int spos,int epos,int num,int *pos)
{
int mid;
if(spos > epos)
{
*pos=-1;
return(0);
}
mid=(epos+spos)/2;
if(*(arr+mid)==num)
{
*pos=mid;
return(1);
}
if(*(arr+mid)> num)
{ return( search(arr,mid+1,epos,num,pos) ); }
if(*(arr+mid) < num)
{ return( search(arr,spos,mid-1,num,pos) ); }
}
Output:
Do u want to enter values to array automaticaly y/n:y
Entered array after sorting is...
100 87 78 65 53 45 31 12 7 5 4 3 2 1 0
Enter the number to be searched:5
Entered number 5 found at position 10
Search again y/n :n
Output:
Number of elements
5
Enter elements
2 4 1 69 41
2 4 1 69 41the partitioning element is :2
swapping 4 & 1
2 1 4 69 41
swapping 4 & 1
2 4 1 69 41
I is gretaer than J,so b[left] and
b[j] are swapped.swapping 2,2
69 4 1 2 41
Ex 34: Write a program in C language to implement 2-way Merge sort using pointers.
Code:
/* Program of sorting using merge sort through recursion*/
#include<stdio.h>
#define MAX 20
int array[MAX];
main()
{
int i,n;
clrscr();
printf("Enter the number of elements : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter element %d : ",i+1);
scanf("%d",&array[i]);
}
printf("Unsorted list is :\n");
for( i = 0 ; i<n ; i++)
printf("%d ", array[i]);
merge_sort( 0, n-1);
printf("\nSorted list is :\n");
for( i = 0 ; i<n ; i++)
printf("%d ", array[i]);
printf("\n");
getch();
}/*End of main()*/
merge_sort( int low, int high )
{ int mid;
if( low != high )
{
mid = (low+high)/2;
merge_sort( low , mid );
merge_sort( mid+1, high );
merge( low, mid, high );
}
}/*End of merge_sort*/
merge( int low, int mid, int high )
{
int temp[MAX];
int i = low;
int j = mid +1 ;
int k = low ;
while( (i <= mid) && (j <=high) )
{
if(array[i] <= array[j])
temp[k++] = array[i++] ;
else
temp[k++] = array[j++] ;
}/*End of while*/
while( i <= mid )
temp[k++]=array[i++];
Output:
Enter the number of elements : 5
Enter element 1 : 88
Enter element 2 : 956
Enter element 3 : 785
Enter element 4 : 456
Enter element 5 : 754
Unsorted list is :
88 956 785 456 754
Sorted list is :
88 456 754 785 956
Output:
Enter the number of elements : 4
Enter element 1 : 45
Enter element 2 : 88
Enter element 3 : 75
Enter element 4 : 6
Unsorted list is : 45 88 75 6
After Pass 1 elements are : 45 75 6 88
After Pass 2 elements are : 45 6 75 88
After Pass 3 elements are : 6 45 75 88
Sorted list is : 6 45 75 88
for(i=1;i<=max_edges;i++)
{
printf("Enter edge %d(0 0 to quit): ",i);
scanf("%d %d",&origin,&destin);
if((origin==0) && (destin==0))
break;
if( origin > n || destin > n || origin<=0 || destin<=0)
{ printf("Invalid edge!\n"); i--; }
else
adj[origin][destin]=1;
}/*End of for*/
}/*End of create_graph()*/
display()
{ int i,j;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
printf("%3d",adj[i][j]);
printf("\n");
} } /*End of display()*/
insert_queue(int node)
{
if (rear==MAX-1)
printf("Queue Overflow\n");
else
{
if (front==-1) /*If queue is initially empty */
front=0;
rear=rear+1;
queue[rear] = node ;
}
}/*End of insert_queue()*/
delete_queue()
{
int del_item;
if (front == -1 || front > rear)
{
printf("Queue Underflow\n");
return ;
} else
{
del_item=queue[front];
front=front+1;
return del_item;
} }/*End of delete_queue() */
int indegree(int node)
{
int i,in_deg=0;
for(i=1;i<=n;i++)
if( adj[i][node] == 1 )
in_deg++;
return in_deg; }/*End of indegree() */
Output:
Enter number of vertices : 3
Enter edge 1(0 0 to quit): 1 3
Enter edge 2(0 0 to quit): 1 2
Enter edge 3(0 0 to quit): 3 2
Enter edge 4(0 0 to quit): 0 0
The adjacency matrix is :
011
000
010
Nodes after topological sorting are :
132