冒泡排序排序后仍可按输入顺序输出

#include <iostream>
using namespace std;
int main()
{
    int a[5];
    for(int i=0;i<5;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<4;i++)
        for(int j=0;j<4-i;j++)
        {
            int temp;
            if(a[j+1]>a[j])
            {
                temp=a[j];
                a[j]=a[j+1];
                a[j+1]=temp;
            }
        }
    for(int i=0;i<5;i++)
    {
      cout<<a[i]<<' ';
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43838785/article/details/89351888