#include<iostream>
using namespace std;
#define type long
typedef int (*compareFunc)(type a,type b);//定义函数指针
void bubble_sort(type* arry,int m,compareFunc func);//申明冒泡函数
int compare(type a,type b);//申明比较函数
#define n 10
void main(){
type arry[n]={8,2,3,4,2,4,8,9,0,1};
bubble_sort(arry,n,compare);
int i = 9;
while(i >= 0){
std::cout<<arry[9-i]<<std::endl;
i--;
}
}
int compare(type a,type b){
if (a > b) return 1;
else if (a == b) return 0;
else return -1;
}
void bubble_sort(type* arry,int m,compareFunc func){
bool flag = true;
int count = 0;
for (int i = 0; (i < m - 1)&&flag==true ; i++)//若不用flag做优化运行次数为9次,用他做优化运行次数为6次。
{
flag = false;
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余1页未读,立即下载