Shopping In MUMBAI

Are you searching for Discounts, offers, sale in Mumbai ? You are in the right place. MUMBAI, a shopping haven, has no dearth of great discounts and sales. This blog features the best MUMBAI shopping offers, sale, discounts and deals and bargains CURRENTLY GOING on in Mumbai plus a few free things thrown in on top. Don't wait for it because once they are gone, they are gone. Hurry!..By clicking the "Like" button you will receive a daily update of discounts, sale, offers going on in Mumbai. LIKE IT.... SHARE IT...njoY.

Sunday, May 31, 2009

Data Structure program Adjacency Matrix or Adjacency Linked List.

Implement Adjacency Matrix or Adjacency Linked List for an undirected or directed graph.

/* Adjacency matrix of undirected graph */

#include
#include

void main()
{
int a[20][20], m, n, i, x, y, j;
clrscr();

printf("Enter total no. of nodes:\n");
scanf("%d",&n);
printf("Enter total no. of edges:\n");
scanf("%d",&m);

/*Initialization of adjacency matrix */
for(i=0;i {
for(j=0;j a[i][j]=0;
}

for(i=1;i<=m;i++)
{
printf("\n Enter nodes of the edge %d ",i);
scanf("%d %d",&x,&y);
a[x-1][y-1]=1;
a[y-1][x-1]=1;
}

printf("\nThe resultant matrix is:-\n");

for(i=0;i {
for(j=0;j printf("%5d",a[i][j]);
printf("\n");
}
getch();
}




OUTPUT:-

Enter total no. of nodes:
4

Enter total no. of edges:
5

Enter nodes of the edge 1 1 3

Enter nodes of the edge 2 3 4

Enter nodes of the edge 3 4 2

Enter nodes of the edge 4 2 1

Enter nodes of the edge 5 1 4

The resultant matrix is:-
0 1 1 1
1 0 0 1
1 0 0 1
1 1 1 0

Data Structure program Adjacency Matrix or Adjacency Linked List.SocialTwist Tell-a-Friend

0 comments:

SUPPORT THIS BLOG