关于排序算法的问题

来源:互联网 发布:哈尔滨网络电视台 编辑:程序博客网 时间:2024/05/16 10:55

程序目的是通过排序算法进行数组由大到小排序

但不同编译器运行结果不一致

#include <iostream>#include <iomanip>  //使用setw()函数using namespace std;//定义无参函数void bubble(int[], int);int main(){    int arry[10] = {11, 4, 55, 6, 77, 8, 9, 0, 7, 1};    cout << "排序前:";    for(int i=0;i<10;++i)    {        cout << arry[i] << setw(3);    }    cout << endl;    bubble(arry, 10);    return 0;}void bubble(int a[], int n){    for(int i=1;i<n;++i)   //排序函数    {        for(int j=0;j<n-i;++j)        {            if(a[j]<a[j+1])            {                int temp;                temp = a[j];                a[j] = a[j+1];                a[j+1] = temp;            }        }    }    cout << "排序后:";     //输出    for(int i=0;i<n;++i)    {        cout << a[i] << setw(5);    }}


codeblocks:




Dev C++:




1 0
原创粉丝点击