锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久一区二区三区国产精品,亚洲神马久久,麻豆影视在线http://www.aygfsteel.com/yinzhao0509/zh-cnSat, 21 Jun 2025 09:39:33 GMTSat, 21 Jun 2025 09:39:33 GMT60鐩存帴鎻掑叆鎺掑簭銆佹姌鍗婃彃鍏ユ帓搴忓拰璧鋒場鎺掑簭綆楁硶鐨刯ava瀹炵幇http://www.aygfsteel.com/yinzhao0509/archive/2008/11/08/239438.htmlzhao yongwangzhao yongwangSat, 08 Nov 2008 10:51:00 GMThttp://www.aygfsteel.com/yinzhao0509/archive/2008/11/08/239438.htmlhttp://www.aygfsteel.com/yinzhao0509/comments/239438.htmlhttp://www.aygfsteel.com/yinzhao0509/archive/2008/11/08/239438.html#Feedback0http://www.aygfsteel.com/yinzhao0509/comments/commentRss/239438.htmlhttp://www.aygfsteel.com/yinzhao0509/services/trackbacks/239438.htmlpackage net.yinzhao.code;

public class Sort {
 
 /**
  * 鎻掑叆鎺掑簭鐨勫熀鏈濇兂涓猴細(xì)棣栧厛瀵繪壘涓涓湁搴忔暟鍒楋紝鐒跺悗灝嗘暟緇勪腑鐨勬瘡涓厓绱犳彃鍏ュ埌璇ユ湁搴忓簭鍒椾腑錛?br />   * 鍒欒鏁扮粍搴忓垪鍗沖彲鍙樹負(fù)鏈夊簭鏁板垪銆傚叿浣撳疄鏂藉姙娉曚負(fù)錛岄閫夊皢絎竴涓厓绱犵湅浣滄槸涓涓湁搴忓簭鍒楋紝鐒跺悗
  * 浠庣浜屼釜鍏冪礌寮濮嬮亶鍘嗘暟緇勶紝灝嗘瘡涓厓绱犳彃鍏ュ埌浠庣涓涓厓绱犲埌鍓嶄竴涓厓绱犵殑鏈夊簭搴忓垪涓紝鍗沖彲瀹?br />   * 鎴愭帓搴忋?br />   * @param temp
  */
 /*
 public static void insertSort(int[] temp)
 {
  int length = temp.length;
  
  for (int i = 1; i < length; i++) // 鎶婄涓涓厓绱犵湅浣滀竴涓湁搴忓簭鍒楋紝浠庣浜屼釜鍏冪礌寮濮嬮亶鍘?br />   {
   int tempNo = temp[i];
   
   for (int j = 0; j < i; j++)
   {
    if (tempNo < temp[j])
    {
     for (int k = i; k > j; k--) // 灝嗗叾閬嶅巻鏁板拰姣旇緝鏁頒箣闂寸殑鏁頒緷嬈″悜鍚庣Щ鍔ㄤ竴浣?br />       temp[k] = temp[k-1];
     temp[j] = tempNo;
    }
   }
  }
 }
 */
 
 /**
  * javaeye涓婄湅鍒扮殑鍙﹀涓縐嶅啓娉曪紝涓嶅悓涔嬪鏄叾涓庡墠杈規(guī)暟瀛椾竴涓竴涓瘮杈冿紝鐒跺悗涓嬈′竴嬈¢愭笎縐誨姩銆?br />   */
 /*
 public static void insertSort(int[] a) 
    { 
        for(int i = 1; i < a.length; i++) 
        { 
            int temp = a[i]; 
            int j = i - 1; 
            while (j >= 0 && temp < a[j]) 
            { 
                a[j+1] = a[j]; 
                j--; 
            } 
            a[j+1] = temp; 
        }  
    }
    */
 
 /**
  * 鏁版嵁緇撴瀯涔︿笂鍘熺増綆楁硶鐨刯ava浠g爜瀹炵幇
  */
 public static void insertSort(int[] temp)
 {
  int j = 0;
  int length = temp.length;
  int[] a = new int[length+1];
  System.arraycopy(temp, 0, a, 1, length);
  for(int i = 2; i < a.length; i++)
  {
   if(a[i] < a[i-1])
   {
    a[0] = a[i];
    a[i] = a[i-1];
    for (j = i - 2; a[i] < a[i-1]; j--)
    {
     a[j+1] = a[j];
    }
    a[j+1] = a[0];
   }
  }
  
  for (int i = 1; i < a.length; i++)
  {
   System.out.println(a[i]);
  }
 }
 
 /**
  * 鎶樺崐鎻掑叆鎺掑簭綆楁硶鐨刯ava瀹炵幇
  * @param temp
  */
 public static void bInsertSort(int[] temp)
 {
  int length = temp.length;
  for (int i = 1; i < length; i++)
  {
   int tempVal = temp[i];
   int low = 0;
   int high = i - 1;
   while (low <= high)
   {
    int middle = (low + high) / 2;
    if (tempVal < temp[middle])
     high = middle - 1;
    else
     low = middle + 1;
   }
   for (int j = i; j > high + 1; j--)
    temp[j] = temp[j-1];
   temp[high+1] = tempVal;
  }
 }
 
 public static void buddleSort(int[] temp)
 {
     for (int i = 0; i < temp.length - 1; i++)
     {
      for (int j = i + 1; j < temp.length; j++)
      {
       if (temp[i] > temp[j])
       {
        int tempVal = temp[i];
        temp[i] = temp[j];
        temp[j] = tempVal;
       }
      }
     }
 }
 
 
 public static void main(String[] args)
 {
  int a[] = {113, 3, 24, 24, 78, 96};
  Sort.bInsertSort(a);
  //Sort.insertSort(a);
  //Sort.buddleSort(a);
  for (int i = 0; i < a.length; i++)
  {
   System.out.println(a[i]);
  }
 }

}



]]>
主站蜘蛛池模板: 从江县| 江安县| 兴城市| 朝阳县| 莎车县| 济宁市| 睢宁县| 义马市| 同德县| 沾化县| 巩留县| 沈阳市| 巴林右旗| 义马市| 周宁县| 周口市| 闽清县| 二连浩特市| 新昌县| 莆田市| 额济纳旗| 东海县| 巴里| 呈贡县| 扶沟县| 莫力| 宜章县| 利津县| 伊吾县| 宜丰县| 大港区| 宜昌市| 彝良县| 宜兴市| 蚌埠市| 巨野县| 来凤县| 白水县| 德昌县| 中方县| 湖北省|