归并排序
发布日期:2022-02-27 02:38:00 浏览次数:70 分类:技术文章

本文共 658 字,大约阅读时间需要 2 分钟。

#include 
using namespace std;void merge(int *a,int s,int e,int *b){ int left_len=(e-s+1)/2+1; int left_index=s; int right_index=s+left_len; int result_index=s; while(left_index
a[e]) { int t=a[s]; a[s]=a[e]; a[e]=t; } return;//必须放在if条件外 } else if(e-s == 0) return; else { sort(a,s,(e-s+1)/2+s,b); sort(a,(e-s+1)/2+s+1,e,b); merge(a,s,e,b); for(int i=s; i<=e; i++) a[i]=b[i]; }}int main(){ int data[] = {9,6,7,22,20,33,16,20}; const int length = 8; int re[length]; sort(data, 0, length-1, re); for(int i=0; i

转载地址:https://blog.csdn.net/weixin_43399464/article/details/90439729 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:UML类图中箭头和线条的含义和用法
下一篇:一 Apache NiFi

发表评论

最新留言

表示我来过!
[***.240.166.169]2024年04月11日 19时08分23秒