Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/thealgorithms/ciphers/Blowfish.java
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ public class Blowfish {
*/
private String hexToBin(String hex) {
String binary = "";
Long num;
long num;
String binary4B;
int n = hex.length();
for (int i = 0; i < n; i++) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/thealgorithms/ciphers/HillCipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ static void validateDeterminant(int[][] keyMatrix, int n) {
System.out.println(
"Invalid key, as determinant = 0. Program Terminated"
);
return;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public static String base2base(String n, int b1, int b2) {
// If the remainder is a digit < 10, simply add it to
// the left side of the new number.
if (decimalValue % b2 < 10) {
output = Integer.toString(decimalValue % b2) + output;
output = decimalValue % b2 + output;
} // If the remainder is >= 10, add a character with the
// corresponding value to the new number. (A = 10, B = 11, C = 12, ...)
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public static void main(String args[]) {
public static int convertOctalToDecimal(String inputOctal) {
try {
// Actual conversion of Octal to Decimal:
Integer outputDecimal = Integer.parseInt(inputOctal, 8);
return outputDecimal;
return Integer.parseInt(inputOctal, 8);
} catch (NumberFormatException ne) {
// Printing a warning message if the input is not a valid octal
// number:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void go() { // shows distance to all vertices // Interactive run for unde
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
Expand All @@ -85,7 +85,7 @@ public void go() { // shows distance to all vertices // Interactive run for unde
// 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private static boolean bipartite(
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]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ int minDist(int dist[], Boolean Set[]) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,7 @@ private boolean adjacencyOfEdgeDoesExist(int from, int to) {
* @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();
}

/**
Expand Down Expand Up @@ -343,14 +339,14 @@ public List<Integer> breadthFirstOrder(int startVertex) {
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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int minKey(int key[], Boolean mstSet[]) {
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;
}
Expand Down Expand Up @@ -80,7 +80,7 @@ void primMST(int graph[][]) {
{
if (
graph[u][v] != 0 &&
mstSet[v] == false &&
!mstSet[v] &&
graph[u][v] < key[v]
) {
parent[v] = u;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private void stronglyConnCompsUtil(int u, int lowTime[], int insertionTime[],
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]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ private void cascadingCuts(HeapNode curr) {
if (!curr.isMarked()) { //stop the recursion
curr.mark();
if (!curr.isRoot()) this.markedHeapNoodesCounter++;
return;
} else {
if (curr.isRoot()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,12 @@ public int peek() {

// returns boolean value whether the heap is empty or not
public boolean isEmpty() {
if (0 == this.size) {
return true;
}
return false;
return 0 == this.size;
}

// returns boolean value whether the heap is full or not
public boolean isFull() {
if (this.size == this.capacity) {
return true;
}
return false;
return this.size == this.capacity;
}

// prints the heap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ private int alloc() {
}

// 2- make the os point to the next of the @var{availableNodeIndex}
int availableNext = cursorSpace[availableNodeIndex].next;
cursorSpace[os].next = availableNext;
cursorSpace[os].next = cursorSpace[availableNodeIndex].next;

// this to indicate an end of the list , helpful at testing since any err
// would throw an outOfBoundException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ public static void main(String[] arg) {
list.insert(3);
list.insertNth(1, 4);
assert list.toString().equals("10->7->5->3->1");
System.out.println(list.toString());
System.out.println(list);
/* Test search function */
assert list.search(10) &&
list.search(5) &&
Expand All @@ -424,7 +424,7 @@ public static void main(String[] arg) {
list.deleteNth(1);
list.delete();
assert list.toString().equals("7->3");
System.out.println(list.toString());
System.out.println(list);
assert list.size == 2 && list.size() == list.count();

list.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,13 @@ public CircularQueue(int size) {
}

public boolean isEmpty() {
if (beginningOfQueue == -1) {
return true;
} else {
return false;
}
return beginningOfQueue == -1;
}

public boolean isFull() {
if (topOfQueue + 1 == beginningOfQueue) {
return true;
} else if (topOfQueue == size - 1 && beginningOfQueue == 0) {
return true;
} else {
return false;
}
} else return topOfQueue == size - 1 && beginningOfQueue == 0;
}

public void enQueue(int value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,12 @@ public void addLast(T val) {
if (tail == null) {
// If the deque is empty, add the node as the head and tail
head = newNode;
tail = newNode;
} else {
// If the deque is not empty, insert the node as the new tail
newNode.prev = tail;
tail.next = newNode;
tail = newNode;
}
tail = newNode;

size++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,6 @@ public static void main(String[] args) {

System.out.println(myQueue.peekFront()); // Will print 2
System.out.println(myQueue.peekRear()); // Will print 7
System.out.println(myQueue.toString()); // Will print [2, 5, 3, 7]
System.out.println(myQueue); // Will print [2, 5, 3, 7]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public void insert(int data) {

private Node insert(Node node, int item) {
if (node == null) {
Node add = new Node(item);
return add;
return new Node(item);
}
if (node.data > item) {
node.left = insert(node.left, item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,20 @@ private void delete(Node node) {
}
return;
}
Node child;
if (node.left != null) {
Node child = node.left;
child = node.left;
while (child.right != null) {
child = child.right;
}
node.key = child.key;
delete(child);
} else {
Node child = node.right;
child = node.right;
while (child.left != null) {
child = child.left;
}
node.key = child.key;
delete(child);
}
node.key = child.key;
delete(child);
}

public void delete(int delKey) {
Expand Down Expand Up @@ -216,11 +215,7 @@ private void reheight(Node node) {

public boolean search(int key) {
Node result = searchHelper(this.root, key);
if (result != null) {
return true;
}

return false;
return result != null;
}

private Node searchHelper(Node root, int key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,9 @@ public void put(int value) {
if (value < parent.data) {
parent.left = newNode;
parent.left.parent = parent;
return;
} else {
parent.right = newNode;
parent.right.parent = parent;
return;
}
}
}
Expand Down Expand Up @@ -177,7 +175,6 @@ else if (temp.left != null && temp.right != null) {
if (temp == root) {
successor.parent = null;
root = successor;
return true;
} // If you're not deleting the root
else {
successor.parent = temp.parent;
Expand All @@ -188,8 +185,8 @@ else if (temp.left != null && temp.right != null) {
} else {
temp.parent.left = successor;
}
return true;
}
return true;
} // One child
else {
// If it has a right child
Expand All @@ -207,7 +204,6 @@ else if (temp.left != null && temp.right != null) {
} else {
temp.parent.right = temp.right;
}
return true;
} // If it has a left child
else {
if (temp == root) {
Expand All @@ -223,8 +219,8 @@ else if (temp.left != null && temp.right != null) {
} else {
temp.parent.right = temp.left;
}
return true;
}
return true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ public void depth(Node node, int dep) {
for (int i = 0; i < node.child.size(); i++) {
depth(node.child.get(i), dep - 1);
}
return;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,23 +309,20 @@ void deleteFixup(Node x) {

public void insertDemo() {
Scanner scan = new Scanner(System.in);
while (true) {
System.out.println("Add items");
System.out.println("Add items");

int item;
Node node;
int item;
Node node;

item = scan.nextInt();
while (item != -999) {
node = new Node(item);
insert(node);
item = scan.nextInt();
while (item != -999) {
node = new Node(item);
insert(node);
item = scan.nextInt();
}
printTree(root);
System.out.println("Pre order");
printTreepre(root);
break;
}
printTree(root);
System.out.println("Pre order");
printTreepre(root);
scan.close();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public boolean delete(String word) {
}
currentNode = node;
}
if (currentNode.end == true) {
if (currentNode.end) {
currentNode.end = false;
return true;
}
Expand Down
Loading