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

View Full Document Right Arrow Icon
/*SUBRAJIT MAITY ROLL NO:-41 SE-CMPN(A) PROGRAM FOR DIJKSTRA ALGORITHIM*/ #include<stdio.h> int v,e; void create(int g[][20],int visited[],int d[],int p[]) { int i,j,a,b,w; printf("Enter no of vertices:"); scanf("%d",&v); printf("Enter no of edges:"); scanf("%d",&e); for(i=1;i<=v;i++) for(j=1;j<=v;j++) g[i][j]=0; for(i=1;i<=v;i++) { p[i]=visited[i]=0; d[i]=32767; } for(i=1;i<=e;i++) { printf("Enter an edge a,b and weight:"); scanf("%d %d %d",&a,&b,&w); g[a][b]=g[b][a]=w; }} void dijkstra(int g[][20],int visited[],int d[],int p[]) { int min,source,dest,current,i,l,x,dc; printf("enter source and destination vertex:"); scanf("%d %d",&source,&dest); current=source; d[source]=0; visited[source]=1; dc=d[current]; while(visited[dest]!=1) { for(i=1;i<=v;i++) { if(g[current][i]!=0) if(visited[i]==0) if(d[i]>g[current][i]+dc) {d[i]=g[current][i]+dc; p[i]=current;} } min=32767; for(i=1;i<=v;i++) { if(visited[i]==0) if(d[i]<min) {
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
min=d[i]; current=i; } } dc=d[current];
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 3


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

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