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

总结1的代码

时间:2017-12-09 19:36:16      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:quic   insert   rgs   插入排序   public   for   string   div   ret   

1:冒泡排序法

package xxx;

public class Effervescency {
public static void main(String[] args){
int a[]={1,22,3,55,6,77,8,99};
int temp=0;
for(int i=0;i<a.length-1;i++){
for(int j=0;j<a.length-1;j++){
if(a[j]>a[j+1]){
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
for(int i=0;i<a.length;i++)
System.out.println(a[i]);
}
}

2:插入排序法
package xxx;
 
public class Insert {
   public static void main (String[] args){
  int a[]={99,8,77,66,5,33,22,11};
  
  int temp=0;
  
  for(int i=1;i
  
  int j=i-1;
  
  temp=a[i];
  
  for(;j>=0&&temp
  
  a[j+1]=a[j];
  
  }
  
  a[j+1]=temp;
  
  }
  for(int i=0;i
  System.out.println(a[i]);
   }
}
3:快速排序法
package xxx;
 
public class QuickSort {  
  
  static int a[]={1,22,3,55,66,7,88,9};  
  
  public static void main(String[] args){  
  
    quick(a);  
  
    for(int i=0;i
  
       System.out.println(a[i]);  
  
}  
  
public static int getMiddle(int[] list, int low, int high) {     
  
            int tmp = list[low];      
  
            while (low < high) {     
  
                while (low < high && list[high] >= tmp) {     
  
                    high--;     
  
                }     
  
                list[low] = list[high];     
  
                while (low < high && list[low] <= tmp) {     
  
                    low++;     
  
                }     
  
                list[high] = list[low];    
  
            }     
  
           list[low] = tmp;               
  
            return low;                       
  
        }    
  
public static void _quickSort(int[] list, int low, int high) {     
  
            if (low < high) {     
  
               int middle = getMiddle(list, low, high);       
  
                _quickSort(list, low, middle - 1);            
  
               _quickSort(list, middle + 1, high);            
  
            }     
  
        }   
  
public static void quick(int[] a2) {     
  
            if (a2.length > 0) {      
  
                _quickSort(a2, 0, a2.length - 1);     
  
        }     
  
       }   
  
}  

总结1的代码

标签:quic   insert   rgs   插入排序   public   for   string   div   ret   

原文地址:http://www.cnblogs.com/11588ab/p/8012121.html

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