Skip to content

Commit 2488a2a

Browse files
authored
Code cleanup (TheAlgorithms#4246)
1 parent 3facb0d commit 2488a2a

52 files changed

Lines changed: 50 additions & 167 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/com/thealgorithms/conversions/OctalToBinary.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
package com.thealgorithms.conversions;
2-
import java.util.Scanner;
32

43
/**
54
* Converts any Octal Number to a Binary Number

src/main/java/com/thealgorithms/datastructures/graphs/TarjansAlgorithm.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.thealgorithms.datastructures.graphs;
22

33
import java.util.ArrayList;
4-
import java.util.Iterator;
54
import java.util.List;
65
import java.util.Stack;
76

src/main/java/com/thealgorithms/datastructures/lists/DoublyLinkedList.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,12 @@ public class DoublyLinkedList {
2828
*/
2929
private LinkOperations linkOperations;
3030

31-
/**
32-
* Size refers to the number of elements present in the list
33-
*/
34-
private int size;
35-
3631
/**
3732
* Default Constructor
3833
*/
3934
public DoublyLinkedList() {
4035
head = null;
4136
tail = null;
42-
size = 0;
4337
}
4438

4539
/**
@@ -55,7 +49,6 @@ public DoublyLinkedList(int[] array) {
5549
for (int i : array) {
5650
linkOperations.insertTail(i, this);
5751
}
58-
size = array.length;
5952
}
6053

6154
/**

src/main/java/com/thealgorithms/datastructures/lists/Merge_K_SortedLinkedlist.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,5 @@ private class Node {
4747

4848
private int data;
4949
private Node next;
50-
51-
public Node(int d) {
52-
this.data = d;
53-
next = null;
54-
}
5550
}
5651
}

src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,7 @@ public Node reverseList(Node node) {
148148
public void clear() {
149149
Node cur = head;
150150
while (cur != null) {
151-
Node prev = cur;
152151
cur = cur.next;
153-
prev = null; // clear to let GC do its work
154152
}
155153
head = null;
156154
size = 0;
@@ -346,9 +344,7 @@ public void delete() {
346344
public void deleteNth(int position) {
347345
checkBounds(position, 0, size - 1);
348346
if (position == 0) {
349-
Node destroy = head;
350347
head = head.next;
351-
destroy = null;
352348
/* clear to let GC do its work */
353349
size--;
354350
return;
@@ -358,10 +354,7 @@ public void deleteNth(int position) {
358354
cur = cur.next;
359355
}
360356

361-
Node destroy = cur.next;
362357
cur.next = cur.next.next;
363-
destroy = null; // clear to let GC do its work
364-
365358
size--;
366359
}
367360

src/main/java/com/thealgorithms/datastructures/stacks/NodeStack.java

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public static void main(String[] args) {
4343
private Item data;
4444

4545
private static NodeStack<?> head;
46-
private NodeStack<?> next;
4746
private NodeStack<?> previous;
4847
private static int size = 0;
4948

@@ -72,7 +71,7 @@ public void push(Item item) {
7271
} else {
7372
newNs.setPrevious(NodeStack.head);
7473
NodeStack.head.setNext(newNs);
75-
NodeStack.head.setHead(newNs);
74+
NodeStack.setHead(newNs);
7675
}
7776

7877
NodeStack.setSize(NodeStack.getSize() + 1);
@@ -86,7 +85,7 @@ public void push(Item item) {
8685
public Item pop() {
8786
Item item = (Item) NodeStack.head.getData();
8887

89-
NodeStack.head.setHead(NodeStack.head.getPrevious());
88+
NodeStack.setHead(NodeStack.head.getPrevious());
9089
NodeStack.head.setNext(null);
9190

9291
NodeStack.setSize(NodeStack.getSize() - 1);
@@ -133,23 +132,11 @@ public void print() {
133132
}
134133
}
135134

136-
/**
137-
* Getters and setters (private)
138-
*/
139-
private NodeStack<?> getHead() {
140-
return NodeStack.head;
141-
}
142-
143135
private static void setHead(NodeStack<?> ns) {
144136
NodeStack.head = ns;
145137
}
146138

147-
private NodeStack<?> getNext() {
148-
return next;
149-
}
150-
151139
private void setNext(NodeStack<?> next) {
152-
this.next = next;
153140
}
154141

155142
private NodeStack<?> getPrevious() {
@@ -171,8 +158,4 @@ private static void setSize(int size) {
171158
private Item getData() {
172159
return this.data;
173160
}
174-
175-
private void setData(Item item) {
176-
this.data = item;
177-
}
178161
}

src/main/java/com/thealgorithms/datastructures/trees/GenericTree.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ private class Node {
2323
}
2424

2525
private Node root;
26-
private int size;
27-
2826
public GenericTree() { // Constructor
2927
Scanner scn = new Scanner(System.in);
3028
root = create_treeG(null, 0, scn);
@@ -44,7 +42,6 @@ private Node create_treeG(Node node, int childindx, Scanner scn) {
4442
int number = scn.nextInt();
4543
for (int i = 0; i < number; i++) {
4644
Node child = create_treeG(node, i, scn);
47-
size++;
4845
node.child.add(child);
4946
}
5047
return node;

src/main/java/com/thealgorithms/datastructures/trees/TreeRandomNode.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ private class Node {
3030

3131
int item;
3232
Node left, right;
33-
34-
public Node(int key) {
35-
item = key;
36-
left = right = null;
37-
}
3833
}
3934

4035
// Using an arraylist to store the inorder traversal of the given binary tree

src/main/java/com/thealgorithms/datastructures/trees/nearestRightKey.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public static void main(String[] args) {
1212
int inputX0 = sc.nextInt();
1313
int toPrint = nearestRightKey(root, inputX0);
1414
System.out.println("Key: " + toPrint);
15+
sc.close();
1516
}
1617

1718
public static NRKTree BuildTree() {

src/main/java/com/thealgorithms/dynamicprogramming/LongestValidParentheses.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.thealgorithms.dynamicprogramming;
22

3-
import java.util.Scanner;
4-
53
/**
64
* Given a string containing just the characters '(' and ')', find the length of
75
* the longest valid (well-formed) parentheses substring.

0 commit comments

Comments
 (0)