基础

位运算

1
2
3
4
5
6
7
8
9
10
11
public class bit_operation {
public static void print(int num) {
for (int i = 31; i >= 0; i--) {
System.out.print((num & (1 << i)) == 0 ? "0" : "1");
}
}

public static void main(String[] args) {
print(-12);
}
}

选择排序

1
2
3
4
5
6
7
8
9
10
11
12
13
public static void selectSort(int[] arr) {
if (arr == null || arr.length == 1) {
return;
}
int N = arr.length;
for (int i = 0; i < N; i++) {
int minValueIndex = i;
for (int j = i + 1; j < N; j++) {
minValueIndex = arr[j] < arr[minValueIndex] ? j : minValueIndex;
}
swap(arr, i, minValueIndex);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
public static void bubbleSort(int[] arr) {
if (arr == null || arr.length == 1) {
return;
}
int N = arr.length;
for (int end = N - 1; end >= 0; end--) {
for (int second = 1; second <= end; second++) {
if (arr[second - 1] > arr[second]) {
swap(arr, second - 1, second);
}
}
}

}

}

}
1
2


数组 链表 跳表

数组是在内存中开辟出一段连续的空间

跳表是为了解决链表的缺点 空间换时间