首页 > 其他 > 详细

选择排序

时间:2014-08-28 13:15:19      阅读:159      评论:0      收藏:0      [点我收藏+]
        public static void main(String[] args)
        {
            //System.out.println("Hello World!");
            int[] arr = { 8, 1, 2, 7, 4, 6, 12, 88, 95, 45, 32, 56 };
            SelectSort(arr);
            PrintArr(arr);
        }
 
        public static void SelectSort(int[] arr)
        {
            for (int x = 0; x < arr.length; x++)
            {
                for (int y = x + 1; y < arr.length; y++)
                {
                    if (arr[x] > arr[y])
                    {
                        int temp = arr[y];
                        arr[y] = arr[x];
                        arr[x] = temp;
                    }
                }
            }
        }
        public static void PrintArr(int[] arr)
	    {
		    System.out.print("[");
		    for(int i=0;i<arr.length;i++)
		    {
			    if(i!=arr.length-1)
			    {
				    System.out.print(arr[i]+", ");
			    }
			    else
			    {
				    System.out.print(arr[i]+"]");
			    }
		    }
	    }      
    }





选择排序

原文:http://www.cnblogs.com/xiaoyongit520/p/3941373.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!