// quick qort and binary search.cpp: 主项目文件。
#include<iostream>
#include<cstdlib>
#include<ctime>
#define SIZE 100
#define SIZE_SEED 100
using namespace std;
/* 交换两个数*/
void swap_f (int& small, int& big)
{ int temp=small;
small=big;
big=temp;
return ;
}
void choice_sort(int arr[], int size)
{
/*
|选择排序,时间复杂度为O(size*size)
*/
for (int i = 0; i<=size; i++)
for(int j=i+1; j<=size; j++)
if (arr[j] < arr[i])
swap_f(arr[j], arr[i]);
}
void main()
{
srand(unsigned int ( time (NULL)));
int iarray[SIZE];
/*
| 生成10个随机数
*/
for ( int ix=0; ix<=SIZE; ix++ )
iarray[ix]=(rand()%SIZE_SEED+1);
choice_sort(iarray, SIZE );
for ( int iy=0; iy<SIZE; iy++ )
cout << iarray[iy] << " ";
cin.get();
return ;
}
选择排序
最新推荐文章于 2024-09-28 22:14:04 发布