[c++]选择排序

来源:互联网 发布:淘宝商家联盟 编辑:程序博客网 时间:2024/05/22 14:53
#include<iostream>using namespace std;const int N=11;int main(){    int i,j,temp,b;    int a[11]={25,36,56,88,96,45,10,33,2,36,155};    for(i=0;i<N-1;i++)    {        temp=i;        for(j=i+1;j<N;j++)        {            if(a[temp]>a[j])                temp=j;        }        if(i!=temp)        {            b=a[temp];            a[temp]=a[i];            a[i]=b;}    }    for(i=0;i<N;i++)        cout<<a[i]<<' ';    cout<<endl;}

0 0
原创粉丝点击