码迷,mamicode.com
首页 > 其他好文 > 详细

选择排序

时间:2014-08-28 13:15:19      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:style   http   color   ar   for   div   sp   ef   c   

        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]+"]");
			    }
		    }
	    }      
    }





选择排序

标签:style   http   color   ar   for   div   sp   ef   c   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!