算法DAY66

今天是去实现了一下排序算法

先是交换排序

最简单的冒泡排序:

#include <stdio.h>

#include <vector>

#include <iostream>

using namespace std;

int main(){

int n;

vector<int> result;

while(cin>>n){

result.push_back(n);

}

int a=0;

for(int i=0;i<result.size();i++){

int flag=0;

for(int j=result.size()-1;j>i;j--){

if(resultj<resultj-1){

int tmp=resultj;

resultj=resultj-1;

resultj-1=tmp;

flag=1;

}

}

if(flag==0)

break;

}

for(int i=0;i<result.size();i++){

cout<<resulti<<" ";

}

}

快速排序:

#include <stdio.h>

#include <vector>

#include <iostream>

using namespace std;

int pattern(vector<int> &a,int low,int high){

int tmp=alow;

while(low<high){

for(;low<high&&ahigh>tmp;high--){

}

swap(alow,ahigh);

for(;low<high&&alow<=tmp;low++){

}

swap(ahigh,alow);

}

alow=tmp;

return low;

}

void quicksort(vector<int> &a,int low,int high){

if(low>=high) return;

int tmp=pattern(a,low,high);

quicksort(a,low,tmp-1);

quicksort(a,tmp+1,high);

}

int main(){

int n;

vector<int> result;

while(cin>>n){

result.push_back(n);

}

quicksort(result,0,result.size()-1);

for(int i=0;i<result.size();i++){

cout<<resulti<<" ";

}

}

相关推荐
星夜离尘5617 分钟前
MATLAB 离散数据分箱:半开区间、末端点与计数、加权和、平均
算法·matlab
Pniubi21 分钟前
力扣76.最小覆盖子串
算法·leetcode·职场和发展
地平线开发者1 小时前
征程6|用 hrt\_model\_exec 看清 YOLOv5x 的输入、原始输出和后处理
人工智能·算法
csdn_aspnet2 小时前
C++ 3个有序点的方向(Orientation of 3 ordered points)
c++·算法
Felven2 小时前
C. Brr Brrr Patapim
c语言·开发语言
赤生云电竞2 小时前
GPU算力共享平台架构实践:任务分发与资源隔离的关键配置
算法·架构·gpu算力
小七在进步3 小时前
string的使用(2)
c++
路溪非溪3 小时前
python标准库使用总结
开发语言·python
青少儿编程课堂3 小时前
蓝桥杯·全国青少年信息素养大赛·电子学会Python/C++考级:折半搜索优化子集枚举(Meet in the Middle)解析
c++·python·算法·bfs·信息学竞赛
SomeOtherTime5 小时前
Rust 面向对象介绍(AI回答)
开发语言·python·rust