您的位置:首页 > 其它

直接插入排序。。。

2010-07-30 09:36 267 查看
#include <cstdlib>
#include <iostream>
#include <ctime>
#include <algorithm>
using namespace std;
const int MAX = 500;
const int COUNT = 10;
void display(int value[], int count)
{
for(int i=0; i<count; i++)
cout << value[i] << " ";
cout << endl;
}
void directInsertSort(int value[], int count)
{
int temp;

for(int i=1; i<count; i++)
{
temp = value[i];

int j = i;
for(; j>0; j--)
{
if(temp < value[j - 1])
value[j] = value[j - 1];
else
break;
}

value[j] = temp;
}
}
int main(int argc, char *argv[])
{
int value[COUNT];

srand((unsigned)time(NULL));

for(int i=0; i<COUNT; i++)
value[i] = rand() % MAX;

cout << "raw data is: " << endl;
display(value, COUNT);

directInsertSort(value, COUNT);
cout << "after direct insert sort: " << endl;
display(value, COUNT);

system("PAUSE");
return EXIT_SUCCESS;
}
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  include insert system null