#include<iostream>
using namespace std;
#include<stdio.h>
#include<stack>
#include<list>
#include<assert.h>
#define BUFFER_SIZE 256
void swap(int *a, int *b)
{
int temp = *b;
*b = *a;
*a = temp;
}
void selectsort(int a[], int n)
{
int i = 0, j, k;
for (int i = 0; i < n - 1; i++)
{
k = i;
for (j = i + 1; j < n; j++)
{
if (a[j] < a[k])
k = j;
}
if (k != i)
{
swap(a[k], a[i]);
}
}
}
void main()
{
int a[] = { 49,38,65,97,76,13,27,49 };
int n = sizeof(a) / sizeof(a[0]);
selectsort(a, n);
for (int i = 0; i < n; ++i)
{
cout << a[i] << " " << endl;
}
}
排序算法:4.选择排序之直接选择排序
最新推荐文章于 2021-08-09 21:27:20 发布