当前位置:网站首页>C language: optimized merge sort
C language: optimized merge sort
2022-07-28 13:36:00 【Nianchi ichthyology programming】
#include <stdio.h>
void showArr(int arr[] , int length);
void mergeSort(int a[] , int alen , int b[] , int blen , int *temp);
int main()
{
int a[5] = {
1,3,5,7,9};
int b[3] = {
2,8,10};
int temp[8];
mergeSort(a,5,b,3,temp);
printf(" The sequence after merging and sorting is :\n");
showArr(temp,8);
return 0;
}
void mergeSort(int a[] , int alen , int b[] , int blen , int *temp)
{
int i , j , k;
i = k = j = 0;
while(i < alen && j < blen)
temp[k++]=a[i]<b[j]?a[i++]:b[j++];
while(i < alen)
temp[k++] = a[i++];
while(j < blen)
temp[k++] = b[j++];
}
void showArr(int arr[] , int length)
{
for(int i = 0 ; i < length ; i++){
printf("%4d",arr[i]);
}
printf("\n");
}
边栏推荐
- C语言:优化后的归并排序
- Have you seen the management area decoupling architecture? Can help customers solve big problems
- C language: random generated number + merge sort
- Parent and child of treeselect
- Rust from introduction to mastery 01 introduction
- gicv3 spi register
- Leetcode notes 118. Yang Hui triangle
- 【C语言】结构体指针与结构体变量作形参的区别
- Volcanic stone investment Zhang Suyang: hard technology, the relatively certain answer in the next 10 years
- Using auto.js to realize the function of fifaol3 mobile terminal card interceptor
猜你喜欢
随机推荐
[ecmascript6] symbol and its related use
Leetcode notes 118. Yang Hui triangle
Aragon creates Dao polygon BSC test network
Have you seen the management area decoupling architecture? Can help customers solve big problems
GO语言-栈的应用-表达式求值
PCP parity principle arbitrage
Paddleclas classification practice record
Map tiles: detailed explanation of vector tiles and grid tiles
Jenkins--持续集成服务器
比XShell更好用、更现代的终端工具!
Rust 从入门到精通01-简介
ES6 null merge operator (?)
Leetcode 笔记 566. 重塑矩阵
The difference between sessionstorage, localstorage and cookies
数据库系统原理与应用教程(062)—— MySQL 练习题:操作题 32-38(六)
火山石投资章苏阳:硬科技,下一个10年相对确定的答案
gicv3 spi register
Night God simulator packet capturing wechat applet
How does the vditor renderer achieve server-side rendering (SSR)?
管理区解耦架构见过吗?能帮客户搞定大难题的








