Skip to content

Commit 40eee1c

Browse files
authored
Merge pull request #1253 from EAlexa/master
optimization
2 parents a45cbeb + 5ce4cc2 commit 40eee1c

File tree

14 files changed

+28
-22
lines changed

14 files changed

+28
-22
lines changed

Conversions/DecimalToBinary.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public static void conventionalConversion() {
3535
n /= 2;
3636
} //converting decimal to binary
3737
System.out.println("\tBinary number: " + b);
38+
input.close();
3839
}
3940

4041
/**

Conversions/RomanToInteger.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44

55
public class RomanToInteger {
66

7-
private static Map<Character, Integer> map = new HashMap<Character, Integer>() {{
7+
private static Map<Character, Integer> map = new HashMap<Character, Integer>() {
8+
/**
9+
*
10+
*/
11+
private static final long serialVersionUID = 87605733047260530L;
12+
13+
{
814
put('I', 1);
915
put('V', 5);
1016
put('X', 10);

DataStructures/Buffers/CircularBuffer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ private int getTrueIndex(int i) {
2626
return i % _buffer_size;
2727
}
2828

29+
2930
public Character readOutChar() {
3031
Character result = null;
3132

33+
3234
//if we have data to read
3335
if (_readable_data.get() > 0) {
34-
result = new Character(_buffer[getTrueIndex(_read_index)]);
36+
37+
result = Character.valueOf(_buffer[getTrueIndex(_read_index)]);
3538
_readable_data.decrementAndGet();
3639
_read_index++;
3740
}

DataStructures/Graphs/ConnectedComponent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public ArrayList<Node> depthFirstSearch(Node n, ArrayList<Node> visited) {
108108
public class ConnectedComponent {
109109

110110
public static void main(String[] args) {
111-
Graph graphChars = new Graph();
111+
Graph<Character> graphChars = new Graph<>();
112112

113113
// Graph 1
114114
graphChars.addEdge('a', 'b');
@@ -123,7 +123,7 @@ public static void main(String[] args) {
123123

124124
graphChars.addEdge('w', 'w');
125125

126-
Graph graphInts = new Graph();
126+
Graph<Integer> graphInts = new Graph<>();
127127

128128
// Graph 2
129129
graphInts.addEdge(1, 2);

DataStructures/Graphs/Cycles.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Cycle {
1010
private int[][] adjacencyMatrix;
1111
private boolean[] visited;
1212
ArrayList<ArrayList<Integer>> cycles = new ArrayList<ArrayList<Integer>>();
13-
private boolean[] finalCycles;
13+
1414

1515
public Cycle() {
1616
Scanner in = new Scanner(System.in);
@@ -34,6 +34,7 @@ public Cycle() {
3434
end = in.nextInt();
3535
adjacencyMatrix[start][end] = 1;
3636
}
37+
in.close();
3738

3839
}
3940

DataStructures/Graphs/PrimMST.java

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

3-
import java.lang.*;
4-
53
/**
64
* A Java program for Prim's Minimum Spanning Tree (MST) algorithm.
75
* adjacency matrix representation of the graph

DataStructures/HashMap/Hashing/LinkedList.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public LinkedList() {
1212

1313
public void insert(int data) {
1414

15-
Node temp = Head;
1615
Node newnode = new Node(data);
1716

1817
size++;

DataStructures/HashMap/Hashing/Main.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ public static void main(String[] args) {
88
int choice, key;
99

1010
HashMap h = new HashMap(7);
11+
Scanner In = new Scanner(System.in);
1112

1213
while (true) {
1314
System.out.println("Enter your Choice :");
1415
System.out.println("1. Add Key");
1516
System.out.println("2. Delete Key");
1617
System.out.println("3. Print Table");
1718
System.out.println("4. Exit");
18-
19-
Scanner In = new Scanner(System.in);
20-
19+
2120
choice = In.nextInt();
2221

2322
switch (choice) {
@@ -39,10 +38,11 @@ public static void main(String[] args) {
3938
break;
4039
}
4140
case 4: {
41+
In.close();
4242
return;
4343
}
4444
}
45-
In.close();
45+
4646
}
4747
}
4848
}

DataStructures/Lists/CursorLinkedList.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
public class CursorLinkedList<T> {
66

7+
78
private static class Node<T> {
89

910
T element;
@@ -13,20 +14,16 @@ private static class Node<T> {
1314
this.element = element;
1415
this.next = next;
1516
}
16-
17-
boolean isEmpty() {
18-
return element == null;
19-
}
2017
}
2118

22-
2319
private final int os;
2420
private int head;
2521
private final Node<T>[] cursorSpace;
2622
private int count;
2723
private final static int CURSOR_SPACE_SIZE = 100;
2824

2925

26+
3027
{
3128
// init at loading time
3229
cursorSpace = new Node[CURSOR_SPACE_SIZE];

DataStructures/Lists/SinglyLinkedList.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ public void deleteNth(int position) {
120120
cur = cur.next;
121121
}
122122

123-
Node destroy = cur.next;
123+
//Node destroy = cur.next;
124124
cur.next = cur.next.next;
125-
destroy = null; // clear to let GC do its work
125+
//destroy = null; // clear to let GC do its work
126126

127127
size--;
128128
}

0 commit comments

Comments
 (0)