Type Here to Get Search Results !

Take an example subnet graph with weights indicating delay between nodes

 Take an example subnet graph with weights indicating delay between nodes


#include<stdio.h> 

#include<conio.h> 

struct full

{

char line[10],dest[10]; int hops;

}f[20];

main()

{

int nv,min,minver,i; char sv[2],temp;

clrscr();

printf("\nEnter number of vertices:"); 

scanf("%d",&nv);

printf("\n Enter source vertex: ");

 scanf("%s",sv);

printf("\n Enter full table for source vertex %s :\n",sv); 

for(i=0;i<nv;i++)

scanf("%s %s %d",f[i].dest,f[i].line,&f[i].hops); 

printf("\n HIERARCHIAL TABLE\n\n"); 

for(i=0;i<nv;)

{

if(sv[0]==f[i].dest[0])

{

printf("\n %s %s %d",f[i].dest,f[i].line,f[i].hops);

 i++;

}

else

{

min=1000; minver=0; temp=f[i].dest[0]; while(temp==f[i].dest[0])

{

if(min>f[i].hops)

{

min=f[i].hops; minver=i;

} i++;

}

printf("\n %c %s %d ",temp,f[minver].line,f[minver].hops);

}

}

getch();

}

 



INPUT/OUTPUT:


Enter number of vertices: 8


Enter source vertex :1A


Enter full table for source vertex 1A

: 1A - - 1B 1B 1

1C 1C 1

2A 1B 1

2B 1B 2

3A 1C 2

3B 1C 3

4A 1C 3 HIERARCHIAL TABLE

1A - 0

1B 1B 1

1C 1C 1

2 1B 1

3 1C 2

4 1C 3


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Featured post

M

M