bubbleSort2.0.h
#include<iostream>
#include<vector>
using namespace std;
template<typename T>
void bubbleSort(vector<T> &v){
int lend=0;//左端截至位置
int rend=v.size()-1;//右端截止位置
int i;//游标
while(lend<rend){
for(i=lend;i<rend;++i){
if(v[i]>v[i+1])
swap(v[i],v[i+1]);
}
--i;
--rend;
for(i;i>lend;--i){
if(v[i]<v[i-1])
swap1(v[i],v[i-1]);
}
++i;
++lend;
}
}
template<typename T>
void swap1(T &a,T &b){
auto temp=a;
a=b;
b=temp;
}
冒泡排序2.0
最新推荐文章于 2023-01-25 17:54:23 发布