Skip to content
This repository was archived by the owner on Feb 29, 2024. It is now read-only.

Commit dd20141

Browse files
committed
Git crashed so I had to redo some stuff
1 parent f77a330 commit dd20141

File tree

2 files changed

+26
-38
lines changed

2 files changed

+26
-38
lines changed

.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>Java</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

src/dining.java

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,36 @@
22
import java.io.*;
33
public class dining {
44
static final int V=9;
5-
int minDistance(int dist[], Boolean sptSet[])
6-
{
7-
8-
int min = Integer.MAX_VALUE, min_index=-1;
9-
5+
static int minDistance(int dist[], Boolean sptSet[]) {
6+
int min = Integer.MAX_VALUE, min_index=-1; // Computers are too stupid to understand infinite
107
for (int v = 0; v < V; v++)
118
if (sptSet[v] == false && dist[v] <= min)
129
{
1310
min = dist[v];
1411
min_index = v;
1512
}
16-
1713
return min_index;
1814
}
19-
void printSolution(int dist[], int n)
20-
{
21-
System.out.println("Vertex Distance from Source");
22-
for (int i = 0; i < V; i++)
23-
System.out.println(i+" tt "+dist[i]);
24-
}
25-
26-
void dijkstra(int graph[][], int src)
27-
{
15+
static void dijkstra(int graph[][], int src) {
2816
int dist[] = new int[V];
29-
3017
Boolean sptSet[] = new Boolean[V];
31-
for (int i = 0; i < V; i++)
32-
{
18+
for (int i = 0; i < V; i++) {
3319
dist[i] = Integer.MAX_VALUE;
3420
sptSet[i] = false;
3521
}
36-
37-
3822
dist[src] = 0;
39-
for (int count = 0; count < V-1; count++)
40-
{
41-
42-
int u = minDistance(dist, sptSet);
43-
44-
45-
sptSet[u] = true;
46-
47-
48-
for (int v = 0; v < V; v++)
49-
50-
51-
23+
for (int count = 0; count < V-1; count++) {
24+
int u = minDistance(dist, sptSet);
25+
sptSet[u] = true;
26+
for (int v = 0; v < V; v++)
5227
if (!sptSet[v] && graph[u][v]!=0 &&
5328
dist[u] != Integer.MAX_VALUE &&
5429
dist[u]+graph[u][v] < dist[v])
5530
dist[v] = dist[u] + graph[u][v];
56-
}
57-
58-
59-
printSolution(dist, V);
31+
}
6032
}
6133
public static void main(String[] args) {
6234
BufferedReader f = new BufferedReader();
6335

6436
}
65-
6637
}

0 commit comments

Comments
 (0)