Skip to content

Instantly share code, notes, and snippets.

⌨️
I may be slow to respond.

Leopold Baik AgustaRC

⌨️
I may be slow to respond.
Block or report user

Report or block AgustaRC

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View StringMemory.java
public class StringMemory {
public static void main(String... args) {
String literal = "loper";
String object = new String("loper");
System.out.println(literal == object);
System.out.println(literal.equals(object));
}
View StringMemoryIntern.java
public class StringMemoryIntern {
public static void main(String... args) {
String literal = "loper";
String object = new String("loper");
String intern = object.intern();
System.out.println(literal == object); // false
System.out.println(literal.equals(object)); // true
System.out.println(literal == intern); // true
View BubbleSort.java
public class BubbleSort {
public static void bubbleSort(int[] arr) {
final int length = arr.length;
for (int i = 0; i < length; i++) {
for (int j = 0; j < length - i; j++) {
if (j + 1 < length && arr[j] > arr[j + 1]) {
arr[j] = arr[j] + arr[j + 1];
arr[j + 1] = arr[j] - arr[j + 1];
arr[j] = arr[j] - arr[j + 1];
View SelectionSort.java
public class SelectionSort {
public static void selectionSort(int[] arr) {
final int length = arr.length;
for (int i = 0; i < length; i++) {
int min = i;
for (int j = i + 1; j < length; j++) {
if (arr[j] < arr[min]) {
min = j;
View InsertionSort.java
public class InsertionSort {
public static void insertionSort(int[] arr) {
final int length = arr.length;
for (int i = 1; i < length; i++) {
final int key = arr[i];
int position = i;
while (position > 0 && key < arr[position - 1]) {
arr[position] = arr[position - 1];
View ShellSort.java
public class ShellSort {
public static void shellSort(int[] arr) {
final int length = arr.length;
int interval = length / 2;
while (interval >= 1) {
for (int i = 0; i < length; i++) {
intervalSort(arr, i, length - 1, interval);
}
View QuickSort.java
public class QuickSort {
public static void quickSort(int[] arr) {
quickSort(arr, 0, arr.length -1);
}
private static void quickSort(int[] arr, int begin, int end) {
if (begin >= end) {
return;
}
View HeapSort.java
public class HeapSort {
public static void heapSort(int[] arr) {
final int length = arr.length;
final Heap heap = new Heap(length);
for (int element : arr) {
heap.insertHeap(element);
}
for (int i = length - 1; i >= 0; --i) {
View MergeSort.java
public class MergeSort {
private static int[] sorted;
public static void mergeSort(int[] arr) {
sorted = new int[arr.length];
mergeSort(arr, 0, arr.length - 1);
}
private static void mergeSort(int[] arr, int begin, int end) {
if (begin < end) {
View RadixSort.java
public class RadixSort {
@SuppressWarnings("unchecked")
private static LinkedList<Integer>[] counter = new LinkedList[] {
new LinkedList<>(), new LinkedList<>(),
new LinkedList<>(), new LinkedList<>(),
new LinkedList<>(), new LinkedList<>(),
new LinkedList<>(), new LinkedList<>(),
new LinkedList<>(), new LinkedList<>() };
You can’t perform that action at this time.