#include <iostream>
using namespace std;
void swap(int * p1, int * p2)
{
int t;
t = *p1;
*p1 = *p2;
*p2 = t;
}
void sort(int sorce[], int n)
{
for (int i=0; i<n; i++)
for (int j=i+1; j<n; j++)
if (sorce[j] < sorce[i])
swap(&sorce[j], &sorce[i]);
}
int main()
{
int a[6] = {1, 2, 3, 9, 5, 6};
sort(a, 6);
for (int i=0; i<6; i++)
{
cout << a[i] << endl;
}
return 0;
}
一个简单的排序算法
最新推荐文章于 2023-07-19 11:18:13 发布