{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

PRIMS - dc=d[current visited[curent]=1 printf"sortest...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include<stdio.h> #include<conio.h> #define j 100 #define max 5 void main() { int p[max]={0,0,0,0,0}; int d[max]={j,j,j,j,j}; int weight[max][max]; int visited[max]={0,0,0,0,0}; int source,dest,curent,i,dc,h,x; clrscr(); printf("\n enter source and destination vertex "); scanf("%d%d",&source,&dest); current=source; d[source]=0;visite[source]=1; dc=d[count]; while(visited[dest]!=1) { for(i=1;i<=max;i++) { if(w[current][i]!=0) if(visited[i]==0) if(d[i]>w[current][i]+dc) { d[i]=w[current][i]+dc; p[i]=current; } } min=i; for(i=1;i<=max;i++) { if(visited[i]==0) if(d[i]<min) { min=d[i]; current=i;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } } dc=d[current]; visited[curent]=1; } printf("sortest distance from %d to %d\n",source,dest); printf("%d\n",d[dest]); printf("path=\n") l=dest; do { x=p[l]; printf("vertex %d connected to %d\n",l,x); l=x; }while(l!=surce); getch(); } /* **************OUTPUT****************** enter the weight matrix 0 800 410 612 0 800 0 2985 300 200 410 2985 0 1421 0 612 300 1421 0 400 0 200 0 400 0 2-5 200 2-4 300 4-1 612 1-3 410 thus the minmum cost is = 1522 */...
View Full Document

{[ snackBarMessage ]}

Page1 / 2

PRIMS - dc=d[current visited[curent]=1 printf"sortest...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon bookmark
Ask a homework question - tutors are online