标签:
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