冒泡演算法(Bubble sort)
v[0]跟v[1]比
如果v[0]比較大就機換位置
#include<bits/stdc++.h>
using namespace std;
void bubblesort(vector<int> &vt){
for(int i=0;i<vt.size()-1;++i){
for(int j=0;j<vt.size()-1;++j){
if(vt[j]>vt[j+1]){
int temp;
v[j]=temp;
v[j+i]=temp;
}
}
for(int k=0;k<vt.size();++k){
cout<<vt[k]<<" "<<endl;
}
}
}
int main(){
vector<int>vt[1,2,3,2,1];
bubblesort(vt);
}
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up