当前位置:网站首页>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");
}
边栏推荐
- org.apache.ibatis.exceptions.TooManyResultsException的异常排查过程
- MySQL practice -- master-slave replication
- C语言:随机生成数+快速排序
- 【黑马早报】字节估值缩水,降至2700亿美元;“二舅”视频作者回应抄袭;任泽平称取消商品房预售制是大势所趋;美联储宣布再加息75个基点...
- Customized template in wechat applet
- C语言:随机生成数+归并排序
- JVM 内存管理 你知道多少
- 《如何打一场数据挖掘赛事》入门版
- Cesium pit -- pit used by various API calls and API itself
- 倒计时 2 天!2022 中国算力大会:移动云邀您共见算力网络,创新发展
猜你喜欢
![[error] after logging in to another machine using SSH, you find that the hostname is still yourself | unable to access yarn8088](/img/81/641a5b3445534fc3b8c87ee6deaa64.png)
[error] after logging in to another machine using SSH, you find that the hostname is still yourself | unable to access yarn8088

屈辱、抗争、逆转,三十年,中国该赢微软一次了

.NET桌面开发的一些思考

Have a part of the game, after NFT is disabled in my world

Some thoughts on.Net desktop development

Guide for using IP phone system and VoIP system

leetcode-136.只出现一次的数字

Bear market spread portfolio

比XShell更好用、更现代的终端工具!

Call / put option price curve
随机推荐
【C语言】结构体指针与结构体变量作形参的区别
Bear market spread portfolio
Definition of option basis
Call / put option price curve
持续(集成--&gt;交付--&gt;部署)
C language: random number + quick sort
[dark horse morning post] byte valuation has shrunk to $270billion; "Second uncle" video author responded to plagiarism; Renzeping said that the abolition of the pre-sale system of commercial housing
Single option trading and cross trade
Leetcode · daily question · 1331. array sequence number conversion · discretization
Risk analysis of option trading
Some thoughts on.Net desktop development
[C language] the difference between structure pointer and structure variable as formal parameters
Le transaction
Resolve browser password echo
Change password, confirm password verification antd
合并表格行---三层for循环遍历数据
Li Kou sword finger offer 51. reverse order pairs in the array
Rust 从入门到精通01-简介
C语言:顺序存储结构的快速排序
我秃了!唯一索引、普通索引我该选谁?