<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    飛艷小屋

    程序--人生--哲學___________________歡迎艷兒的加入

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      52 Posts :: 175 Stories :: 107 Comments :: 0 Trackbacks

    public?class?Sort?{

    ??public?void?swap(int?a[],?int?i,?int?j)?{
    ????int?tmp?=?a[i];
    ????a[i]?=?a[j];
    ????a[j]?=?tmp;
    ??}

    ??public?int?partition(int?a[],?int?low,?int?high)?{
    ????int?pivot,?p_pos,?i;
    ????p_pos?=?low;
    ????pivot?=?a[p_pos];
    ????for?(i?=?low?+?1;?i?<=?high;?i++)?{
    ??????if?(a[i]?>?pivot)?{
    ????????p_pos++;
    ????????swap(a,?p_pos,?i);
    ??????}
    ????}
    ????swap(a,?low,?p_pos);
    ????return?p_pos;
    ??}

    ??public?void?quicksort(int?a[],?int?low,?int?high)?{
    ????int?pivot;
    ????if?(low?<?high)?{
    ??????pivot?=?partition(a,?low,?high);
    ??????quicksort(a,?low,?pivot?-?1);
    ??????quicksort(a,?pivot?+?1,?high);
    ????}

    ??}

    ??public?static?void?main(String?args[])?{
    ????int?vec[]?=?new?int[]?{?37,?47,?23,?-5,?19,?56?};
    ????int?temp;
    ????//選擇排序法(Selection?Sort)
    ????long?begin?=?System.currentTimeMillis();
    ????for?(int?k?=?0;?k?<?1000000;?k++)?{
    ??????for?(int?i?=?0;?i?<?vec.length;?i++)?{
    ????????for?(int?j?=?i;?j?<?vec.length;?j++)?{
    ??????????if?(vec[j]?>?vec[i])?{
    ????????????temp?=?vec[i];
    ????????????vec[i]?=?vec[j];
    ????????????vec[j]?=?temp;
    ??????????}
    ????????}

    ??????}
    ????}
    ????long?end?=?System.currentTimeMillis();
    ????System.out.println("選擇法用時為:"?+?(end?-?begin));
    ????//打印排序好的結果
    ????for?(int?i?=?0;?i?<?vec.length;?i++)?{
    ??????System.out.println(vec[i]);
    ????}
    ????//??冒泡排序法(Bubble?Sort)
    ????begin?=?System.currentTimeMillis();
    ????for?(int?k?=?0;?k?<?1000000;?k++)?{
    ??????for?(int?i?=?0;?i?<?vec.length;?i++)?{
    ????????for?(int?j?=?i;?j?<?vec.length?-?1;?j++)?{
    ??????????if?(vec[j?+?1]?>?vec[j])?{
    ????????????temp?=?vec[j?+?1];
    ????????????vec[j?+?1]?=?vec[j];
    ????????????vec[j]?=?temp;
    ??????????}
    ????????}

    ??????}
    ????}
    ????end?=?System.currentTimeMillis();
    ????System.out.println("冒泡法用時為:"?+?(end?-?begin));
    ????//打印排序好的結果
    ????for?(int?i?=?0;?i?<?vec.length;?i++)?{
    ??????System.out.println(vec[i]);
    ????}

    ????//插入排序法(Insertion?Sort)
    ????begin?=?System.currentTimeMillis();
    ????for?(int?k?=?0;?k?<?1000000;?k++)?{
    ??????for?(int?i?=?1;?i?<?vec.length;?i++)?{
    ????????int?j?=?i;
    ????????while?(vec[j?-?1]?<?vec[i])?{
    ??????????vec[j]?=?vec[j?-?1];
    ??????????j--;
    ??????????if?(j?<=?0)?{
    ????????????break;
    ??????????}
    ????????}
    ????????vec[j]?=?vec[i];
    ??????}
    ????}
    ????end?=?System.currentTimeMillis();
    ????System.out.println("插入法用時為:"?+?(end?-?begin));
    ????//打印排序好的結果
    ????for?(int?i?=?0;?i?<?vec.length;?i++)?{
    ??????System.out.println(vec[i]);
    ????}

    ????//快速排序法(Quick?Sort)

    ????Sort?s?=?new?Sort();
    ????begin?=?System.currentTimeMillis();
    ????for?(int?k?=?0;?k?<?1000000;?k++)?{
    ??????s.quicksort(vec,?0,?5);
    ????}
    ????end?=?System.currentTimeMillis();
    ????System.out.println("快速法用時為:"?+?(end?-?begin));
    ????//打印排序好的結果
    ????for?(int?i?=?0;?i?<?vec.length;?i++)?{
    ??????System.out.println(vec[i]);
    ????}
    ??}

    }

    posted on 2006-06-05 10:24 天外飛仙 閱讀(234) 評論(0)  編輯  收藏 所屬分類: 算法數據結構

    只有注冊用戶登錄后才能發表評論。


    網站導航:
    博客園   IT新聞   Chat2DB   C++博客   博問  
     
    主站蜘蛛池模板: 亚洲Av永久无码精品黑人| 久久亚洲熟女cc98cm| 亚洲av无码日韩av无码网站冲| 91免费福利精品国产| 亚洲AV无码成人精品区天堂| a在线观看免费视频| 国产亚洲A∨片在线观看| 羞羞视频免费网站在线看| 77777亚洲午夜久久多人| a级毛片免费在线观看| 久久亚洲AV无码精品色午夜麻| baoyu777永久免费视频| 老司机亚洲精品影院无码| www视频免费看| 亚洲综合中文字幕无线码| 岛国片在线免费观看| 国产精品亚洲精品久久精品| 亚洲片国产一区一级在线观看| 国产做国产爱免费视频| 亚洲小视频在线观看| 日本免费网址大全在线观看| 亚洲欧洲无码AV不卡在线| 亚洲国产成人久久笫一页| 日本视频在线观看永久免费| 亚洲视频一区二区三区| 在线不卡免费视频| 国产日韩AV免费无码一区二区三区| 国产亚洲精品成人a v小说| 69视频在线是免费观看| 亚洲乱码国产乱码精华| 国产亚洲精品激情都市| 四虎1515hh永久久免费| 亚洲AV无码精品国产成人| 亚洲人精品午夜射精日韩| 59pao成国产成视频永久免费| 久久亚洲精品国产亚洲老地址| 亚洲Av无码国产情品久久| 久久久久免费精品国产小说| 亚洲一区二区三区高清在线观看| 一级毛片直播亚洲| 99视频精品全部免费观看|