实现选择排序算法
- package page48;
- publicclass SelectionSorter {
- privateint min;
-
- publicvoid Sort(int []arr){
- for(int i = 0;i<arr.length-1;i++){
- min = i;
- for(int j = i+1;j<arr.length;j++){
- if(arr[j]<arr[min]){
- min = j;
- }
- }
- int t = arr[min];
- arr[min] = arr[i];
- arr[i] = t;
- }
- }
-
- publicstaticvoid main(String[] args) {
- int arry[] = newint[]{1,3,4,7,32,88,99,334,100};
- SelectionSorter s = new SelectionSorter();
- s.Sort(arry);
- for(int i = 0;i<arry.length;i++){
- System.out.println(arry[i]);
- }
- }
- }
posted @
2012-03-28 11:08
cyjch
阅读(
391)
评论()
编辑
收藏
举报