Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7563373
  • 博文数量: 961
  • 博客积分: 15795
  • 博客等级: 上将
  • 技术积分: 16612
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-07 14:23
文章分类

全部博文(961)

文章存档

2016年(1)

2015年(61)

2014年(41)

2013年(51)

2012年(235)

2011年(391)

2010年(181)

分类: Java

2012-04-20 22:37:47


点击(此处)折叠或打开

  1. public class NumSort {
  2.     public static void main(String[] args) {
  3.         int[] a = new int[args.length];
  4.         for (int i=0; i<args.length; i++) {
  5.             a[i] = Integer.parseInt(args[i]);
  6.         }
  7.         print(a);
  8.         selectionSort(a);
  9.         print(a);
  10.     }
  11.     
  12.     private static void selectionSort(int[] a) {
  13.         int k, temp;
  14.         for(int i=0; i<a.length; i++) {
  15.             k = i;
  16.             for(int j=k+1; j<a.length; j++) {
  17.                 if(a[j] < a[k]) {
  18.                     k = j;
  19.                 }
  20.             }
  21.             
  22.             if(k != i) {
  23.                 temp = a[i];
  24.                 a[i] = a[k];
  25.                 a[k] = temp;
  26.             }
  27.         }
  28.     }
  29.     
  30.     private static void print(int[] a) {
  31.         for(int i=0; i<a.length; i++) {
  32.             System.out.print(a[i] + " ");
  33.         }
  34.         System.out.println();
  35.     }
  36. }

源码: Array.rar   
 
课件: 数组.pdf   
阅读(1144) | 评论(0) | 转发(1) |
0

上一篇:QT 曲线绘制

下一篇:Java String类

给主人留下些什么吧!~~