真正的冒泡排序

来源:互联网 发布:美工岗位职责是那些 编辑:程序博客网 时间:2024/06/01 09:03
/* * Copyright (c) 2013, 烟台大学计算机学院* All rights reserved.* 作    者:张梦佳* 完成日期:2013 年 12 月2 日* 版 本 号:v1.0** 输入描述:* 问题描述:* 程序输出:冒泡排序* 问题分析:* 算法设计:*/#include <iostream>using namespace std;void bubble_sort(int a[],int);   //用冒泡法按降序排序a中元素void output_array(int s[],int);   //输出排序后的数组int main( ){    int a[20]= {86,76,62,58,77,85,92,80,96,88,77,67,80,68,88,87,64,59,61,76};    int b[15]= {27,61,49,88,4,20,28,31,42,62,64,14,88,27,73};    bubble_sort(a,20);   //用冒泡法按降序排序a中元素    output_array(a,20);    cout<<endl;  //输出排序后的数组    bubble_sort(b,15);   //用冒泡法按降序排序b中元素    output_array(b,15);    cout<<endl;   //输出排序后的数组    return 0;}void bubble_sort(int a[],int n){    int i,z;    double b;    for(i=0;i<n-1;i++)    {        for(z=0;z<n-i-1;z++)        if(a[z]<a[z+1])        {            b=a[z];            a[z]=a[z+1];            a[z+1]=b;        }    }}void output_array(int s[],int n){    int i;    for(i=0; i<n; i++)    {        cout<<s[i]<<" ";    }}


感悟

老是过界。。。。。。