This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean equals(Object anObject) { | |
if (this == anObject) { | |
return true; | |
} | |
if (anObject instanceof String) { | |
String aString = (String)anObject; | |
if (coder() == aString.coder()) { | |
return isLatin1() ? StringLatin1.equals(value, aString.value) | |
: StringUTF16.equals(value, aString.value); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static boolean equals(byte[] value, byte[] other) { | |
if (value.length == other.length) { | |
for (int i = 0; i < value.length; i++) { | |
if (value[i] != other[i]) { | |
return false; | |
} | |
} | |
return true; | |
} | |
return false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BinarySearchTree { | |
private TreeNode<Integer> rootNode; | |
public void init(int[] values) { | |
if (values.length == 0) { | |
return; | |
} | |
TreeNode<Integer> visitedNode; | |
this.rootNode = new TreeNode<>(values[0]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TreeNode<E> { | |
private E value; | |
private TreeNode<E> leftNode; | |
private TreeNode<E> rightNode; | |
public TreeNode(E value) { | |
this.value = value; | |
} | |
public E getValue() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Matrix { | |
private int[][] data; | |
public Matrix(int[][] data) { | |
this.data = data; | |
} | |
public void add(Matrix matrix) { | |
int[][] array = matrix.data; | |
if (data.length != array.length || data[0].length != array[0].length) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ArrayListQueue<E> implements IQueue<E> { | |
private Object[] elements; | |
private int frontIndex = -1; | |
private int rearIndex = -1; | |
public ArrayListQueue() { | |
this.elements = new Object[0]; | |
} | |
public ArrayListQueue(int capacity) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ArrayListStack<E> implements IStack<E> { | |
private Object[] elements; | |
private int size; | |
public ArrayListStack() { | |
this.elements = new Object[0]; | |
} | |
public ArrayListStack(int capacity) { | |
this.elements = new Object[capacity]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LinkedList<E> { | |
private Node<E> first; | |
private Node<E> last; | |
private int size; | |
public int size() { | |
return this.size; | |
} | |
public E getFirst() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class QuickSort { | |
public static void sort(int[] data) { | |
sort(data, 0, data.length - 1); | |
} | |
private static void sort(int[] data, int startIndex, int endIndex) { | |
if (startIndex >= endIndex) { | |
return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ShellSort { | |
private static int roundStepCount = 0; | |
private static int allStepCount = 0; | |
public static void sort(int[] data) { | |
for (int gap = data.length / 2; gap > 0; gap /= 2) { | |
for (int startIndex = 0; startIndex < gap; startIndex++) { | |
insertionSort(data, startIndex, gap); | |
} |
NewerOlder