My Profile

I, Das ShrikKrishna J. MCA III IMSCD&R, Ahmednagar.
Showing posts with label Adjuncy Matrix. Show all posts
Showing posts with label Adjuncy Matrix. Show all posts

Monday, 15 August 2011

Adjuncy Matrix

#include<stdio.h>
struct node
{
int vertex;
struct node * next;
}*v[10];
void createmat(int m[10][10],int n)
{
int i,j;
char ans;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
m[i][j]=0;
if(i!=j)
{
printf("is there any edge between vertex %d and %d(1,0):",i+1,j+1);
scanf("%d",&m[i][j]);
}
}
}
void isempty(int m[10][10],int n)
{
int i,j;
printf("\nthe adjacency matrix is:\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf("\t%d",m[i][j]);
printf("\n");
}
}
void createlist(int m[10][10],int n)
{
int i,j;
struct node *temp,*newnode;
for(i=0;i<n;i++)
{
v[i]=NULL;
for(j=0;j<n;j++)
{
if(m[i][j]==1)
{
newnode=(struct node*)malloc(sizeof(struct node));
newnode->next=NULL;
newnode->vertex=j+1;
if(v[i]==NULL)
v[i]=temp=newnode;
else
{
temp->next=newnode;
temp=newnode;
}
}
}
}
}
void displist(int n)
{
struct node *temp;
int i;
printf("\n adjacency list is \n");
for(i=0;i<n;i++)
{
printf("\n v%d->",i+1);
temp=v[i];
while(temp)
{
printf("v%d->",temp->vertex);
temp=temp->next;
}
printf("NULL");
}
}
void main()
{
int m[10][10],n;
clrscr();
printf("\n enter the no of vertex:");
scanf("%d",&n);
createmat(m,n);
isempty(m,n);
createlist(m,n);
displist(n);
getch();
}

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | cheap international calls