算法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<<" ";

}

}

相关推荐
Julien200424 分钟前
管理机密(一)
运维·服务器·开发语言·学习方法
Chen_harmony27 分钟前
七、STL与string类
开发语言·c++
沐晓时光33 分钟前
C语言入门,字符串和字符串函数知识讲解
c语言·开发语言
xxxiugou1231 小时前
C++命名空间与引用全解析
开发语言·c++
风影同志783241 小时前
20 个比特能装下多少行情?——实测拆解 Kronos 的 K 线分词器
算法
写的都是BUG2 小时前
APK 里的钥匙,一直就放在门口:聊聊加固真正该做什么
前端·算法
用户7624117567052 小时前
第十五章 人工智能基础
c++
地平线开发者2 小时前
CLIP 的零样本分类:一组文本如何变成图像分类器?
算法
yangmu32032 小时前
编程语言发展简史:从机器指令到智能协作
开发语言
京东云开发者3 小时前
从“会生成”到“能生产”:萤火虫 AIGC 平台的 AI Infra 实践
算法·aigc·产品