mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 06:23:08 +08:00
Remove unnecessary code (#4141)
This commit is contained in:
@ -74,7 +74,7 @@ start vertex, end vertex and weights. Vertices should be labelled with a number
|
||||
for (i = 0; i < v - 1; i++) {
|
||||
for (j = 0; j < e; j++) {
|
||||
if (
|
||||
(int) dist[arr[j].u] != Integer.MAX_VALUE &&
|
||||
dist[arr[j].u] != Integer.MAX_VALUE &&
|
||||
dist[arr[j].v] > dist[arr[j].u] + arr[j].w
|
||||
) {
|
||||
dist[arr[j].v] = dist[arr[j].u] + arr[j].w; // Update
|
||||
@ -85,7 +85,7 @@ start vertex, end vertex and weights. Vertices should be labelled with a number
|
||||
// Final cycle for negative checking
|
||||
for (j = 0; j < e; j++) {
|
||||
if (
|
||||
(int) dist[arr[j].u] != Integer.MAX_VALUE &&
|
||||
dist[arr[j].u] != Integer.MAX_VALUE &&
|
||||
dist[arr[j].v] > dist[arr[j].u] + arr[j].w
|
||||
) {
|
||||
neg = 1;
|
||||
|
@ -28,7 +28,7 @@ public class BipartiteGrapfDFS {
|
||||
for (Integer it : adj.get(node)) {
|
||||
if (color[it] == -1) {
|
||||
color[it] = 1 - color[node];
|
||||
if (bipartite(V, adj, color, it) == false) {
|
||||
if (!bipartite(V, adj, color, it)) {
|
||||
return false;
|
||||
}
|
||||
} else if (color[it] == color[node]) {
|
||||
|
@ -12,7 +12,7 @@ class dijkstras {
|
||||
int min = Integer.MAX_VALUE, min_index = -1;
|
||||
|
||||
for (int r = 0; r < k; r++) {
|
||||
if (Set[r] == false && dist[r] <= min) {
|
||||
if (!Set[r] && dist[r] <= min) {
|
||||
min = dist[r];
|
||||
min_index = r;
|
||||
}
|
||||
|
@ -154,11 +154,7 @@ class AdjacencyMatrixGraph {
|
||||
* @return whether or not the vertex exists
|
||||
*/
|
||||
public boolean vertexDoesExist(int aVertex) {
|
||||
if (aVertex >= 0 && aVertex < this.numberOfVertices()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return aVertex >= 0 && aVertex < this.numberOfVertices();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -343,14 +339,14 @@ class AdjacencyMatrixGraph {
|
||||
public String toString() {
|
||||
String s = " ";
|
||||
for (int i = 0; i < this.numberOfVertices(); i++) {
|
||||
s = s + String.valueOf(i) + " ";
|
||||
s = s + i + " ";
|
||||
}
|
||||
s = s + " \n";
|
||||
|
||||
for (int i = 0; i < this.numberOfVertices(); i++) {
|
||||
s = s + String.valueOf(i) + " : ";
|
||||
s = s + i + " : ";
|
||||
for (int j = 0; j < this.numberOfVertices(); j++) {
|
||||
s = s + String.valueOf(this._adjacency[i][j]) + " ";
|
||||
s = s + this._adjacency[i][j] + " ";
|
||||
}
|
||||
s = s + "\n";
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ class PrimMST {
|
||||
int min = Integer.MAX_VALUE, min_index = -1;
|
||||
|
||||
for (int v = 0; v < V; v++) {
|
||||
if (mstSet[v] == false && key[v] < min) {
|
||||
if (!mstSet[v] && key[v] < min) {
|
||||
min = key[v];
|
||||
min_index = v;
|
||||
}
|
||||
@ -80,7 +80,7 @@ class PrimMST {
|
||||
{
|
||||
if (
|
||||
graph[u][v] != 0 &&
|
||||
mstSet[v] == false &&
|
||||
!mstSet[v] &&
|
||||
graph[u][v] < key[v]
|
||||
) {
|
||||
parent[v] = u;
|
||||
|
@ -114,7 +114,7 @@ public class TarjansAlgorithm {
|
||||
stronglyConnCompsUtil(n, lowTime, insertionTime, isInStack, st, graph);
|
||||
//update lowTime for the current node comparing lowtime of adj node
|
||||
lowTime[u] = Math.min(lowTime[u], lowTime[n]);
|
||||
} else if (isInStack[n] == true) {
|
||||
} else if (isInStack[n]) {
|
||||
//If adj node is in stack, update low
|
||||
lowTime[u] = Math.min(lowTime[u], insertionTime[n]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user