#include <stdio.h>
#include <stdlib.h>
#include<iostream>
using namespace std;
int main()
{
int a[7];
for(int i=0;i<5;i++)
{
cin>>a[i];
}
int flag=1;
for(int i=0;i<5;i++)
{
int temp=a[i];
for(int j=i;j<5;j++)
{
if(temp>a[j+1])
{
int t=temp;
temp=a[j+1];
a[j+1]=t;
}
}
a[i]=temp;
}
for(int i=0;i<5;i++)
{
cout<<a[i]<<" ";
}
}
简单选择排序
例如 5 8 1 6 2
第一个位置应该放1
第二个位置应该放2
第三个位置应该放5
第四个位置应该放6
第五个位置应该放5
用两个循环,第一个 for(int i=0;i<5;i++) 循环 代表数字,
第二个for(int j=i;j<5;j++)循环代表循环次数