现在的位置: 首页 > 综合 > 正文

排序

2018年02月16日 ⁄ 综合 ⁄ 共 1900字 ⁄ 字号 评论关闭

 
@font-face{
font-family:"Times New Roman";
}
@font-face{
font-family:"宋体";
}
@font-face{
font-family:"Symbol";
}
@font-face{
font-family:"Arial";
}
@font-face{
font-family:"黑体";
}
@font-face{
font-family:"Courier New";
}
@font-face{
font-family:"Wingdings";
}
p.0{
margin:0pt;
margin-bottom:0.0001pt;
layout-grid-mode:char; text-align:justify;
font-size:10.5000pt; font-family:'Times New Roman'; }
div.Section0{
margin-top:72.0000pt;
margin-bottom:72.0000pt;
margin-left:90.0000pt;
margin-right:90.0000pt;
size:612.0000pt 792.0000pt;
}

冒泡排序(bubble sort):每一次比较,将最大值放在最后,再次比较时,比较范围缩小一位

插入排序法(insert sort):(1)首先比较头两个元素的大小,并排序(2)将下一元素插入排好序的数组中,从最后一个比较,一边比较,一边插入,直至比它小的而停止。(3) 重复(2)

快速排序法(quick sort):(1)选择一个分界值,大于等于分界值的元素集中到数组的某一部分,小于分界值的元素集中到数组的另一部分。(2)对于分出来的部分,重复这个过程,直到数组被排序完毕

@font-face{
font-family:"Times New Roman";
}
@font-face{
font-family:"宋体";
}
@font-face{
font-family:"Symbol";
}
@font-face{
font-family:"Arial";
}
@font-face{
font-family:"黑体";
}
@font-face{
font-family:"Courier New";
}
@font-face{
font-family:"Wingdings";
}
@font-face{
font-family:"新宋体";
}
p.0{
margin:0pt;
margin-bottom:0.0001pt;
layout-grid-mode:char; text-align:justify;
font-size:10.5000pt; font-family:'Times New Roman'; }
div.Section0{
margin-top:72.0000pt;
margin-bottom:72.0000pt;
margin-left:90.0000pt;
margin-right:90.0000pt;
size:595.3000pt 841.9000pt;
}

// bubble sort

// vc 2005 express

#include <iostream>

using namespace std;

void bubble(char arr[], int len);

int main()

{   

 char arr[5] = {'b','e','d','c','a'};

 int len = 5;

 int i;

 for( i=0;i<len;i++)

     cout << arr[i] << " ";

 cout << endl;

 bubble(arr, len);

}

void bubble(char arr[], int len)

{

 int i,j,temp;

 for( i=0; i<(len-1);i++)

 {

       for(j=0;j<(len-i-1);j++)

    {

     if( arr[j]>arr[j+1] )

     {

              temp = arr[j+1];

     arr[j+1] = arr[j];

     arr[j] = temp;

     }

    }

    forint k=0;k<len;k++)

         cout << arr[k] << " ";

    cout << endl;

    }

}

/*

b e d c a

b d c a e

b c a d e

b a c d e

a b c d e

*/

////////////////////////////////////


【上篇】
【下篇】

抱歉!评论已关闭.