码迷,mamicode.com
首页 > 编程语言 > 详细

排序函数

时间:2016-07-21 17:37:19      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

 1 public static void insertionSort(int arr [])
 2 {
 3     for (int i=0; i<arr.length-1 ;i++ )
 4     {
 5         for ( int j=i+1;j>0 ;j-- )
 6         {
 7             if (arr [j-1]<=arr [j])
 8                 break;
 9             int temp= arr [j-1];
10             arr [j-1] = arr [j];
11             arr [j] = temp;
12         }
13     }
14 }
 1 public static void bubbleSort(int arr[])
 2 {
 3     for (int a = 0;a < arr.length;a++ )
 4     {
 5         for (int b = 0;b < arr.length-1;b++ )
 6         {
 7             if (arr[b]>arr[b+1])
 8             {
 9                 int x = arr[b+1];
10                 arr [b+1]=arr [b];
11                 arr [b] = x;
12             }
13         }        
14     }
15 }
 1 public static void selectionSort(int recive[])
 2 {
 3     int x ;
 4     for (int i = 0;i < recive.length-1;i++ )
 5     {
 6         for(int j=i+1; j<recive.length;j++)
 7         {
 8             if (recive [i]> recive [j])
 9             {
10                 x = recive [i];                   //数值互换
11                 recive [i]  = recive [j];
12                 recive [j] = x;
13             }
14         }
15     }
16 }

 

排序函数

标签:

原文地址:http://www.cnblogs.com/x3408/p/5692266.html

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