题解 | #双栈排序#
双栈排序
http://www.nowcoder.com/practice/d0d0cddc1489476da6b782a6301e7dec
import java.util.*;
public class TwoStacks {
public ArrayList<Integer> twoStacksSort(int[] numbers) {
ArrayList<Integer> list = new ArrayList<>();
int tmp;
// 冒泡排序
for (int i = 0; i < numbers.length -1; i++) {
for (int j = 0; j < numbers.length-1-i; j++) {
if (numbers[j] < numbers[j+1]){
tmp = numbers[j];
numbers[j] = numbers[j+1];
numbers[j+1] = tmp;
}
}
}
for (int number : numbers) list.add(number);
return list;
}
}