选择排序

来源:互联网 发布:编程原本 pdf 编辑:程序博客网 时间:2024/06/06 01:42
private void selectSort() {    ArrayList<Integer> dataSource = new ArrayList<Integer> ();    
    dataSource .add(1);
    dataSource .add(5);    
    dataSource .add(9);
    dataSource .add(7);  
    dataSource .add(13);
    dataSource .add(2);
    dataSource .add(8);
    dataSource .add(18);
for (int i = 0, len = dataSource.size(); i < len; i++) {    // 当前拿出比较的数据    int value = dataSource.get(i);
    int litterIndex = i;    for (intj = i + 1; j < len; j++) {        int tempValue = dataSource.get(j);        if (tempValue < value) {            litterIndex = j;        }    }    if (i != litterIndex) {        Integer obj = dataSource.get(litterIndex);        dataSource.set(litterIndex, value);        dataSource.set(i, obj);    }}
Log.i("@@@@", dataSource.toString());
}
0 0