Skip to content

Commit 8521019

Browse files
committed
Replaced <>() with ()
1 parent b547aca commit 8521019

File tree

54 files changed

+92
-92
lines changed

Some content is hidden

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

54 files changed

+92
-92
lines changed

Chp. 01 - Arrays and Strings/__Intro_ArrayList/IntroArrayList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
public class IntroArrayList {
88
/* Merges 2 arrays into an ArrayList */
99
public static ArrayList<String> merge(String[] words, String[] moreWords) {
10-
ArrayList<String> result = new ArrayList<>();
10+
ArrayList<String> result = new ArrayList();
1111
for (String word : words) {
1212
result.add(word);
1313
}

Chp. 02 - Linked Lists/_2_1_Remove_Dups/RemoveDups.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
public class RemoveDups {
99
static void removeDuplicates(Node head) {
10-
Set<Integer> set = new HashSet<>();
10+
Set<Integer> set = new HashSet();
1111
set.add(head.data);
1212
Node n = head;
1313
while (n.next != null) {

Chp. 02 - Linked Lists/_2_5_Sum_Lists/SumLists.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public static Node addForwardOrder(Node m, Node n) {
4040
return n;
4141
}
4242

43-
Stack<Integer> stack1 = new Stack<>();
44-
Stack<Integer> stack2 = new Stack<>();
43+
Stack<Integer> stack1 = new Stack();
44+
Stack<Integer> stack2 = new Stack();
4545

4646
while (m != null) {
4747
stack1.push(m.data);

Chp. 03 - Stacks and Queues/_3_2_Stack_Min/StackMin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
public class StackMin {
88
// Can alternatively use ArrayDeque (it's faster)
9-
Stack<Integer> stack = new Stack<>();
10-
Stack<Integer> minStack = new Stack<>(); // keeps track of minimums
9+
Stack<Integer> stack = new Stack();
10+
Stack<Integer> minStack = new Stack(); // keeps track of minimums
1111

1212
// Always push onto stack. If it's a minimum, also push it onto minStack
1313
void push(int x) {

Chp. 03 - Stacks and Queues/_3_3_Stack_of_Plates/StackOfPlates.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import java.util.Stack; // can alternatively use ArrayDeque (it's faster)
77

88
public class StackOfPlates {
9-
private ArrayList<Stack<Integer>> stacks = new ArrayList<>();
9+
private ArrayList<Stack<Integer>> stacks = new ArrayList();
1010
private int capacity = 3;
1111

1212
/* Implemented to work like a standard push */
@@ -15,7 +15,7 @@ public void push(int data) {
1515
if (lastStack != null && lastStack.size() < capacity) {
1616
lastStack.push(data);
1717
} else {
18-
Stack<Integer> anotherStack = new Stack<>(); // crucial step. Stacks aren't magically created 4 u.
18+
Stack<Integer> anotherStack = new Stack(); // crucial step. Stacks aren't magically created 4 u.
1919
anotherStack.push(data);
2020
stacks.add(anotherStack);
2121
}

Chp. 03 - Stacks and Queues/_3_4_Queue_via_Stacks/QueueViaStacks.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
import java.util.Stack;
1414

1515
public class QueueViaStacks<T> {
16-
private Stack<T> stack1 = new Stack<>();
17-
private Stack<T> stack2 = new Stack<>();
16+
private Stack<T> stack1 = new Stack();
17+
private Stack<T> stack2 = new Stack();
1818

1919
public int size() {
2020
return stack1.size() + stack2.size();

Chp. 03 - Stacks and Queues/_3_4_Queue_via_Stacks/Tester.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class Tester {
66
public static void main(String[] args) {
77
System.out.println("*** Test 3.4: Queue via Stacks\n");
88
System.out.println("elements we will be inserting: 1, 2, 3, 4, 5\n");
9-
QueueViaStacks<Integer> myQueue = new QueueViaStacks<>();
9+
QueueViaStacks<Integer> myQueue = new QueueViaStacks();
1010
myQueue.add(1);
1111
myQueue.add(2);
1212
myQueue.add(3);

Chp. 03 - Stacks and Queues/_3_5_Sort_Stack/SortStack.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public class SortStack {
88
public static Stack<Integer> sort(Stack<Integer> stack) {
9-
Stack<Integer> helperStack = new Stack<>(); // can alternatively use ArrayDeque (it's faster)
9+
Stack<Integer> helperStack = new Stack(); // can alternatively use ArrayDeque (it's faster)
1010
while (!stack.isEmpty()) {
1111
Integer curr = stack.pop(); // saving the top of the stack is one of the main tricks.
1212
while (!helperStack.isEmpty() && curr < helperStack.peek()) {

Chp. 03 - Stacks and Queues/_3_5_Sort_Stack/Tester.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
public class Tester {
88
public static void main(String[] args) {
99
System.out.println("*** Test 3.6: Sort Stack\n");
10-
Stack<Integer> stackToSort = new Stack<>();
10+
Stack<Integer> stackToSort = new Stack();
1111
stackToSort.push(3);
1212
stackToSort.push(7);
1313
stackToSort.push(2);

Chp. 03 - Stacks and Queues/_3_6_Animal_Shelter/AnimalShelter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
public class AnimalShelter {
88
int barcode = 0;
9-
ArrayDeque<Cat> cats = new ArrayDeque<>();
10-
ArrayDeque<Dog> dogs = new ArrayDeque<>();
9+
ArrayDeque<Cat> cats = new ArrayDeque();
10+
ArrayDeque<Dog> dogs = new ArrayDeque();
1111

1212
public void enqueue(Animal animal) {
1313
animal.barcode = barcode++;

Chp. 04 - Trees and Graphs/_4_01_Route_Between_Nodes/RouteBetweenNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static boolean routeExists(GraphNode start, GraphNode end) {
1313
return true;
1414
}
1515

16-
Deque<GraphNode> deque = new ArrayDeque<>(); // use deque as a queue
16+
Deque<GraphNode> deque = new ArrayDeque(); // use deque as a queue
1717
start.visit();
1818
deque.add(start);
1919

Chp. 04 - Trees and Graphs/_4_03_List_of_Depths/ListOfDepths.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
public class ListOfDepths {
99
public static List<List<Integer>> levelOrder(TreeNode root) {
10-
List<List<Integer>> lists = new ArrayList<>();
10+
List<List<Integer>> lists = new ArrayList();
1111
if (root == null) {
1212
return lists;
1313
}
14-
ArrayDeque<TreeNode> deque = new ArrayDeque<>(); // use deque as a queue
14+
ArrayDeque<TreeNode> deque = new ArrayDeque(); // use deque as a queue
1515
deque.add(root);
1616
while (!deque.isEmpty()) {
1717
int numNodesInLevel = deque.size();

Chp. 04 - Trees and Graphs/_4_07_Build_Order/BuildOrder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private static Deque<Node> topoSort(Graph graph) throws Exception {
2727
source.addDirectedNeighbor(node);
2828
}
2929

30-
Deque<Node> result = new ArrayDeque<>();
30+
Deque<Node> result = new ArrayDeque();
3131
topoSortDFS(source, result);
3232
result.removeFirst(); // removes the source node we created
3333
return result;

Chp. 04 - Trees and Graphs/_4_07_Build_Order/Graph.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import java.util.*;
66

77
public class Graph {
8-
List<Node> nodes = new ArrayList<>();
9-
Map<String, Node> map = new HashMap<>();
8+
List<Node> nodes = new ArrayList();
9+
Map<String, Node> map = new HashMap();
1010

1111
public void addDirectedEdge(String s1, String s2) {
1212
Node source = map.get(s1);

Chp. 04 - Trees and Graphs/_4_07_Build_Order/Node.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Node {
1212
public Node(String data) {
1313
this.data = data;
1414
status = Visited.NEW;
15-
neighbors = new ArrayList<>();
15+
neighbors = new ArrayList();
1616
}
1717

1818
public void addDirectedNeighbor(Node neighbor) {

Chp. 04 - Trees and Graphs/_4_09_BST_Sequences/BSTSequences.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
public class BSTSequences {
99
public static List<Deque<Integer>> allSequences(TreeNode node) {
10-
List<Deque<Integer>> results = new ArrayList<>();
10+
List<Deque<Integer>> results = new ArrayList();
1111

1212
if (node == null) {
1313
results.add(new ArrayDeque<Integer>()); // crucial. So the code labeled "weave lists" works properly
1414
return results;
1515
}
1616

17-
Deque<Integer> prefix = new ArrayDeque<>();
17+
Deque<Integer> prefix = new ArrayDeque();
1818
prefix.add(node.data);
1919

2020
// Recursive Cases

Chp. 04 - Trees and Graphs/_4_11_Random_Node/BST.java

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

55
class BST {
66
Node root = null;
7-
RandomizedCollection<Node> collection = new RandomizedCollection<>();
7+
RandomizedCollection<Node> collection = new RandomizedCollection();
88

99
public void insert(int value) {
1010
Node item = new Node(value);

Chp. 04 - Trees and Graphs/_4_11_Random_Node/RandomizedCollection.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
public class RandomizedCollection<T> {
88
Random rand = new Random();
9-
List<T> list = new ArrayList<>();
10-
Map<T, Set<Integer>> valToIndices = new HashMap<>();
9+
List<T> list = new ArrayList();
10+
Map<T, Set<Integer>> valToIndices = new HashMap();
1111

1212
public void add(T item) {
1313
// update Map
1414
if (!valToIndices.containsKey(item)) {
15-
valToIndices.put(item, new HashSet<>());
15+
valToIndices.put(item, new HashSet());
1616
}
1717
valToIndices.get(item).add(list.size());
1818

Chp. 04 - Trees and Graphs/_4_12_Paths_with_Sum/PathWithSums.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
public class PathWithSums {
1010
public static int findSum(TreeNode node, int targetSum) {
11-
Map<Integer, Integer> map = new HashMap<>();
11+
Map<Integer, Integer> map = new HashMap();
1212
map.put(0, 1);
1313
return findSum(node, targetSum, 0, map);
1414
}

Chp. 07 - Object-Oriented Design/_7_01_Deck_of_Cards/Deck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public T dealCard() {
2323
}
2424

2525
public LinkedList<T> dealHand(int numCards) {
26-
LinkedList<T> cards = new LinkedList<>();
26+
LinkedList<T> cards = new LinkedList();
2727
for (int i = 0; i < numCards; i++) {
2828
cards.add(deck.remove());
2929
}

Chp. 07 - Object-Oriented Design/_7_12_Hash_Table/Hash.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public Hash() {
2020

2121
private void initializeLists(ArrayList<LinkedList<Cell<K, V>>> lists) {
2222
for (int i = 0; i < numBuckets; i++) {
23-
lists.add(new LinkedList<>());
23+
lists.add(new LinkedList());
2424
}
2525
}
2626

Chp. 07 - Object-Oriented Design/_7_12_Hash_Table/Main.java

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

55
public class Main {
66
public static void main(String[] args) {
7-
Hash<Integer, String> map = new Hash<>();
7+
Hash<Integer, String> map = new Hash();
88
map.put(2, "Bob");
99
System.out.print(map);
1010
System.out.println("Hash numBuckets = " + map.numBuckets + "\n");

Chp. 08 - Recursion and Dynamic Programming/_8_02_Robot_in_a_Grid/RobotInAGrid.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ public static List<Point> findPath(final boolean[][] maze, int row, int col) {
2222
}
2323

2424
// Create path to save solution into
25-
List<Point> path = new ArrayList<>();
25+
List<Point> path = new ArrayList();
2626
path.add(new Point(0, 0));
2727

2828
// Create cache to save solutions to subproblems
29-
Map<Point, Boolean> cache = new HashMap<>(); // requires overriding .equals() and .hashCode for Point, for HashMap to work properly
29+
Map<Point, Boolean> cache = new HashMap(); // requires overriding .equals() and .hashCode for Point, for HashMap to work properly
3030
cache.put(new Point(0, 0), true); // base case
3131

3232
// Recursively calculate answer
@@ -86,8 +86,8 @@ public static List<List<Point>> allPaths(boolean[][] maze, int row, int col) {
8686
if (maze == null || row >= maze.length || col >= maze[0].length) {
8787
return null;
8888
}
89-
List<List<Point>> solutionPaths = new ArrayList<>();
90-
getAllPaths(maze, 0, 0, solutionPaths, new ArrayList<>());
89+
List<List<Point>> solutionPaths = new ArrayList();
90+
getAllPaths(maze, 0, 0, solutionPaths, new ArrayList());
9191
return solutionPaths;
9292
}
9393

@@ -109,7 +109,7 @@ public static void getAllPaths(boolean[][] maze, int row, int col, List<List<Poi
109109
}
110110

111111
private static void deepCopyPathIntoSolutions(List<Point> path, List<List<Point>> solutionPaths) {
112-
List<Point> solutionPath = new ArrayList<>();
112+
List<Point> solutionPath = new ArrayList();
113113
for (int i = 0; i < path.size(); i++) {
114114
Point point = path.get(i);
115115
solutionPath.add(new Point(point.x, point.y));

Chp. 08 - Recursion and Dynamic Programming/_8_04_Power_Set/PowerSet.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
public class PowerSet {
88
public static List<List<Integer>> getSubsets(int[] array) {
99
if (array == null || array.length == 0) {
10-
return new ArrayList<>();
10+
return new ArrayList();
1111
}
12-
List<List<Integer>> solutions = new ArrayList<>();
13-
makeSubsets(array, 0, solutions, new ArrayList<>());
12+
List<List<Integer>> solutions = new ArrayList();
13+
makeSubsets(array, 0, solutions, new ArrayList());
1414
return solutions;
1515
}
1616

Chp. 08 - Recursion and Dynamic Programming/_8_06_Towers_of_Hanoi/Tower.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Tower {
1010
public int towerNum;
1111

1212
public Tower(int towerNum) {
13-
disks = new ArrayDeque<>();
13+
disks = new ArrayDeque();
1414
this.towerNum = towerNum;
1515
}
1616

Chp. 08 - Recursion and Dynamic Programming/_8_07_Permutations_without_Dups/PermutationsWithoutDups.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
public class PermutationsWithoutDups {
88
public static List<List<Integer>> permute(int[] array) {
99
if (array == null || array.length == 0) {
10-
return new ArrayList<>();
10+
return new ArrayList();
1111
}
12-
List<List<Integer>> solutions = new ArrayList<>();
13-
permute(array, 0, new boolean[array.length], solutions, new ArrayList<>());
12+
List<List<Integer>> solutions = new ArrayList();
13+
permute(array, 0, new boolean[array.length], solutions, new ArrayList());
1414
return solutions;
1515
}
1616

Chp. 08 - Recursion and Dynamic Programming/_8_08_Permutations_with_Dups/PermutationsWithDups.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
public class PermutationsWithDups {
88
public static List<List<Integer>> permute(int[] array) {
99
if (array == null || array.length == 0) {
10-
return new ArrayList<>();
10+
return new ArrayList();
1111
}
12-
Set<List<Integer>> solutions = new HashSet<>();
13-
permute(array, 0, new boolean[array.length], solutions, new ArrayList<>());
12+
Set<List<Integer>> solutions = new HashSet();
13+
permute(array, 0, new boolean[array.length], solutions, new ArrayList());
1414
return new ArrayList<>(solutions);
1515
}
1616

Chp. 08 - Recursion and Dynamic Programming/_8_09_Parens/Parens.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public class Parens {
88
public static List<String> generateParentheses(int n) {
9-
List<String> solutions = new ArrayList<>();
9+
List<String> solutions = new ArrayList();
1010
addParenthesis(new char[n * 2], 0, n, n, solutions);
1111
return solutions;
1212
}

Chp. 08 - Recursion and Dynamic Programming/_8_12_Eight_Queens/EightQueens.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ public static List<List<String>> solveNQueens(int n) {
1010
for (char[] row : board) {
1111
Arrays.fill(row, '.');
1212
}
13-
Set<Integer> cols = new HashSet<>(); // columns |
14-
Set<Integer> d1 = new HashSet<>(); // diagonals \
15-
Set<Integer> d2 = new HashSet<>(); // diagonals /
13+
Set<Integer> cols = new HashSet(); // columns |
14+
Set<Integer> d1 = new HashSet(); // diagonals \
15+
Set<Integer> d2 = new HashSet(); // diagonals /
1616

17-
List<List<String>> solutions = new ArrayList<>();
17+
List<List<String>> solutions = new ArrayList();
1818
placeQueens(board, n, solutions, 0, cols, d1, d2);
1919
return solutions;
2020
}
@@ -48,7 +48,7 @@ private static void placeQueens(char[][] board, int n, List<List<String>> soluti
4848
}
4949

5050
private static List<String> makeSolutionBoard(char[][] board) {
51-
List<String> solution = new ArrayList<>();
51+
List<String> solution = new ArrayList();
5252
for (char[] row : board) {
5353
solution.add(new String(row));
5454
}

Chp. 08 - Recursion and Dynamic Programming/_8_13_Stack_of_Boxes/Tester.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
public class Tester {
88
public static void main(String[] args) {
99
System.out.println("*** Test 8.13: Stack of Boxes\n");
10-
List<Box> boxes = new LinkedList<>();
10+
List<Box> boxes = new LinkedList();
1111
boxes.add(new Box(3, 4, 1));
1212
boxes.add(new Box(8, 6, 2));
1313
boxes.add(new Box(4, 8, 3));

Chp. 10 - Sorting and Searching/_10_02_Group_Anagrams/GroupAnagrams.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class GroupAnagrams {
1212
// key: the sorted version of the String.
1313
// value: all the unsorted Strings that sort to the key.
1414
public static void groupAnagrams(String[] array) {
15-
HashMap<String, List<String>> map = new HashMap<>();
15+
HashMap<String, List<String>> map = new HashMap();
1616

1717
// Group words by Anagram (by putting into HashMap)
1818
for (String str : array) {
@@ -45,7 +45,7 @@ private static String sortChars(String str) {
4545
// Our key will represent the number of letters in each string, where each letter has a separator in it.
4646
// - Example: `aabccc` becomes `2-1-3-...0-` (where the `...` is for the remaining 22 characters)
4747
public static void groupAnagrams2(String[] array) {
48-
HashMap<String, List<String>> map = new HashMap<>();
48+
HashMap<String, List<String>> map = new HashMap();
4949

5050
// Group words by Anagram (by putting into HashMap)
5151
for (String str : array) {

Chp. 16 - More Problems (Moderate)/_16_11_Diving_Board/DivingBoard.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public class DivingBoard {
88
public static List<Integer> allLengths(int k, int shorter, int longer) {
9-
List<Integer> lengths = new ArrayList<>();
9+
List<Integer> lengths = new ArrayList();
1010
for (int numShorter = 0; numShorter <= k; numShorter++) {
1111
int numLonger = k - numShorter;
1212
int length = numShorter * shorter + numLonger * longer;

0 commit comments

Comments
 (0)