2.选择排序

复制代码
#include <iostream>
#include <cstdio>
using namespace std;

const int Maxm = 1000 + 2;
int n[Maxm]; 

int main()
{
    int m;
    scanf("%d", &m);
    for(int i = 1; i <= m; i++)
        scanf("%d", &n[i]);
    
    for(int i = 1; i <= m; i++)
    {
        int key = i;
        for(int r = i + 1; r <= m; r++)
            if(n[r] < n[key])  key = r;
        swap(n[i], n[key]);
    }
    
    for(int i = 1; i <= m; i++)
    printf("%d ", n[i]);
    printf("\n");
    return 0;
} //时间复杂度:O(n2) 
复制代码

冒泡排序的小范围优化(我实在不知道冒泡怎么写了,所以可能会有误解, 欢迎指正)

posted @ 2016-09-08 10:41  筱陌  阅读(138)  评论(0编辑  收藏  举报