教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 学前教育 >

面试必考题目+各种排序实例及点评(2)

来源:网络收集 时间:2026-05-20
导读: cout f.归并排序: #include void Merge(int a[],int tmp[],int lPos,int rPos,int rEnd) { int i,lEnd,NumElements,tmpPos; lEnd=rPos-1; tmpPos=lPos; NumElements=rEnd-lPos+1; while (lPos void msort(int a[],

cout<<\ print_array(a,9); select_sort(a,9); cout<<\ print_array(a,9); }

f.归并排序:

#include

void Merge(int a[],int tmp[],int lPos,int rPos,int rEnd) { int i,lEnd,NumElements,tmpPos; lEnd=rPos-1; tmpPos=lPos; NumElements=rEnd-lPos+1; while (lPos<=lEnd&&rPos<=rEnd) { if (a[lPos]<=a[rPos]) tmp[tmpPos++]=a[lPos++]; else tmp[tmpPos++]=a[rPos++]; } while(lPos<=lEnd) tmp[tmpPos++]=a[lPos++]; while(rPos<=rEnd) tmp[tmpPos++]=a[rPos++]; for(i=0;i

void msort(int a[],int tmp[],int low,int high) { if (low>=high) return; int middle=(low+high)/2; msort(a,tmp,low,middle); msort(a,tmp,middle+1,high); Merge(a,tmp,low,(middle+1),high); }

void merge_sort(int a[],int len) { int *tmp=NULL; tmp=new int[len]; if (tmp!=NULL) {

msort(a,tmp,0,len-1); delete[]tmp; } }

void print_array(int a[],int len) { for (int i=0;iint main() { int a[5]={8,6,1,3,5}; merge_sort(a,5); print_array(a,5); return 0; }

面试必考题目+各种排序实例及点评(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/598623.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)