/*
* 程序的版权和版本声明部分
* Copyright (c)2012, 烟台大学计算机学院学生
* All rightsreserved.
* 文件名称: array.cpp
* 作 者: 王锴英
* 完成日期: 2012年 12月1 日
* 版本号: v1.0
* 输入描述:10个整数
* 问题描述:用冒泡法排序
*/
#include<iostream>
using namespace std;
int bubble_sort(int a[],int s);
void output_array(int a[],int s);
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);
output_array(a,20);
bubble_sort(b,15);
output_array(b,15);
return 0;
}
int bubble_sort(int a[],int s){
int i,j,k;
for(i=0;i<s;i++){
for(j=1;j<s-i;j++)
if(a[j-1]<a[j]){
k=a[j];
a[j]=a[j-1];
a[j-1]=k;
}
}
return a[s];
}
void output_array(int a[],int s){
int i;
cout<<"ナナミトハラ鬟コ"<<endl;
for(i=0;i<s;i++)
cout<<a[i]<<" ";
cout<<endl;
return ;
}
运行结果: