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

}

}

相关推荐
云和数据.ChenGuang4 分钟前
LLM大模型对接本地Ollama部署模型
开发语言·人工智能·python·langchain
荆棘鸟智能12 分钟前
短历时洪水预报算法实践:水文模型与 LightGBM 残差订正融合
人工智能·算法·机器人
等我调个Bug17 分钟前
C++智能指针通俗讲解
开发语言·c++
黑化旺仔34 分钟前
【OC】Runtime:类元数据、加载初始化与消息派发
开发语言·macos·ios·objective-c
Felven42 分钟前
C. Removing Smallest Multiples
c语言·开发语言
云和数据.ChenGuang1 小时前
光哥说Python 循环导入(Circular Import)深度解析:成因、排查与解决方案
开发语言·前端·人工智能·python·langchain
葫三生1 小时前
关于三生原理系列被技术开发社区批量收录或引发策展边界讨论的一种思考
大数据·人工智能·深度学习·算法·机器学习·数据挖掘·开源
catcatuncle1 小时前
OpenWorkBuddy 部署排错手册:从源码启动到自己搭一个给团队用,七个最容易卡住的地方
算法
星夜离尘561 小时前
MATLAB 工程实验:滞回加持续时间报警,把 UNKNOWN 留在状态机里
开发语言·matlab
avi91111 小时前
【AI教人】在Inspector显示所有Delegate-Odin Inspector之三
java·前端·算法·delegate·inspector·editor扩展·unity editor