INDEGREE OUTDEGREE & TOTAL DEGREE OF VERTEX IN GRAPH
INDEGREE
OUTDEGREE
TOTAL DEGREE
OF VERTEX IN GRAPH
//graph
//indegree outdegree and total degree
#include<stdio.h>
int main ()
{
int a[10][10],i,j,in,out,total,n;
printf("plz enter the no of vertices:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=0;
if(i!=j)
{
printf("is edge between %d and %d :",i+1,j+1);
scanf("%d",&a[i][j]);
}
}
}
printf("\nvertex indegree outdegree totaldegree\n");
for(i=0;i<n;i++)
{
in=out=total=0;
for(j=0;j<n;j++)
{
in=in+a[j][i];
out=out+a[i][j];
total=in+out;
}
printf("%4d\t%4d\t%4d\t%4d",i+1,in,out,total);
printf("\n");
}
}
Graph Adjecency list :
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int vertex;
struct node *next;
}NODE;
NODE *list[10];
int CreateList(int m[10][10],int n)
{
int i,j;
struct node *temp, *newnode;
for(i=0;i<n;i++)
{
list[i]=NULL;
for(j=0;j<n;j++)
{
if(m[i][j]==1)
{
newnode=(NODE *)malloc(sizeof(NODE));
newnode->vertex=j+1;
newnode->next=NULL;
if(list[i]==NULL)
list[i]=temp=newnode;
else
{
temp->next=newnode;
temp=newnode;
}
}
}
}
}
int DisplayList( int m[10][10],int n)
{
struct node *temp;
int i;
printf("\n The adjacency list is :\n");
for(i=0;i<n;i++)
{
printf("\nv%d->",i+1);
temp=list[i];
while(temp)
{
printf("v%d->",temp->vertex);
temp=temp->next;
}
printf("NULL");
}
}
int main()
{
int m[10][10]={{0,0,0,1},
{0,0,1,0},
{0,0,0,1},
{1,1,0,0}};
CreateList(m,4);
DisplayList(m,4);
}
Comments
Post a Comment
hey