当前位置:网站首页>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");
}
边栏推荐
猜你喜欢

Unity—“合成大西瓜”小游戏笔记

MySQL practice -- master-slave replication

蓝桥集训(附加面试题)第七天

我抄底了被清算的NFT,却被OpenSea上了锁

Intra prediction and transform kernel selection based on Neural Network

Leetcode-190. inverting binary bits

Customized template in wechat applet

I miss the year of "losing" Li Ziqi

Le transaction

Using auto.js to realize the function of fifaol3 mobile terminal card interceptor
随机推荐
微念“失去”李子柒的这一年
GO语言-栈的应用-表达式求值
C语言学生成绩管理系统详解[通俗易懂]
PHP generates random numbers (nickname random generator)
Bear market spread portfolio
PCP parity principle arbitrage
什么是事务及数据库的优化方法
Customized template in wechat applet
Guide for using IP phone system and VoIP system
Call / put option price curve
C语言:优化后的归并排序
屈辱、抗争、逆转,三十年,中国该赢微软一次了
Dry goods -- encapsulated anti shake and throttling method in the project
gicv3 spi register
How much do you know about JVM memory management
One track education, PHP training, unity of knowledge and practice, popular
Extended operator
Can second uncle cure young people's spiritual internal friction?
Cesium pit -- pit used by various API calls and API itself
Leetcdoe-342. Power of 4