数据结构

#冒泡排序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public class  {
public static void main(String[] args) {
int a[] = { 12, 23, 435, 6, 2, 4, 543, 226, 595 };

for (int j = 0; j < a.length; j++) {
for (int i = 0; i < a.length; i++) {
// 把最大的交换到最后面去
int temp;
if (a[i] > a[j]) {
temp = a[j];
a[j] = a[i];
a[i] = temp;
}
}
}
for (int k = 0; k < a.length; k++) {
System.out.println(a[k]);
}
}
}

#选择排序