Skip to content

Commit bb17fac

Browse files
New Commit
1 parent e03d0b3 commit bb17fac

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

Dijkstra's_algo.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
#define INFINITY 9999
33
#define MAX 10
44

5-
void Dijkstra(int Graph[MAX][MAX], int n, int start);
6-
75
void Dijkstra(int Graph[MAX][MAX], int n, int start) {
86
int cost[MAX][MAX], distance[MAX], pred[MAX];
97
int visited[MAX], count, mindistance, nextnode, i, j;
@@ -53,9 +51,23 @@ void Dijkstra(int Graph[MAX][MAX], int n, int start) {
5351
}
5452
int main() {
5553
int Graph[MAX][MAX], i, j, n, u;
56-
n = 7;
5754

58-
Graph[0][0] = 0;
55+
printf("Enter number of vertices in the graph : ");
56+
scanf("%d", &n);
57+
58+
for(i=0;i<n;i++){
59+
for(j=0;j<n;j++){
60+
if(i==j){
61+
printf("Enter weight of self-loop on vertex %d : ", i);
62+
scanf("%d", &Graph[i][i]);
63+
continue;
64+
}
65+
printf("Enter weight of edge between vertices %d and %d : ", i, j);
66+
scanf("%d", &Graph[i][j]);
67+
}
68+
}
69+
70+
/* Graph[0][0] = 0;
5971
Graph[0][1] = 0;
6072
Graph[0][2] = 1;
6173
Graph[0][3] = 2;
@@ -110,8 +122,9 @@ int main() {
110122
Graph[6][4] = 0;
111123
Graph[6][5] = 1;
112124
Graph[6][6] = 0;
113-
114-
u = 0;
125+
*/
126+
printf("Enter source vertex : ");
127+
scanf("%d", &u);
115128
Dijkstra(Graph, n, u);
116129

117130
return 0;

Dijkstra's_algo.exe

40.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)