当前位置:网站首页>C language: merge sort
C language: 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 = 0;
int j = 0;
int k = 0;
while(i < alen && j < blen){
if(a[i]<b[j]){
temp[k] = a[i];
i++;
k++;
}else{
temp[k] = b[j];
k++;
j++;
}
}
while(i < alen){
temp[k] = a[i];
k++;
i++;
}
while(j < blen){
temp[k] = b[j];
k++;
j++;
}
}
void showArr(int arr[] , int length)
{
for(int i = 0 ; i < length ; i++){
printf("%4d",arr[i]);
}
printf("\n");
}
边栏推荐
- leetcode-136.只出现一次的数字
- Rust from introduction to mastery 01 introduction
- Intrinsic value and time value of options
- 合并表格行---三层for循环遍历数据
- 数据库系统原理与应用教程(062)—— MySQL 练习题:操作题 32-38(六)
- What is the optimization method of transaction and database
- MySQL practice -- master-slave replication
- [apue] 文件中的空洞
- gicv3 spi register
- Why is crypto game changing the game industry?
猜你喜欢

为什么说Crypto游戏正在改变游戏产业?

从手机厂高位“出走”的三个男人

Change password, confirm password verification antd

接口调不通,如何去排查?没想到10年测试老鸟栽在这道面试题上

Humiliation, resistance, reversal, 30 years, China should win Microsoft once
![[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

管理区解耦架构见过吗?能帮客户搞定大难题的

GameStop熊市杀入NFT交易,老牌游戏零售商借Web3焕发第二春

倒计时 2 天!2022 中国算力大会:移动云邀您共见算力网络,创新发展

Three men "running away" from high positions in the mobile phone factory
随机推荐
Redis —— 基础篇
org.apache.ibatis.exceptions.TooManyResultsException的异常排查过程
力扣 2354. 优质数对的数目
Humiliation, resistance, reversal, 30 years, China should win Microsoft once
FFT wave simulation
Is azvudine, a domestic oral new coronal drug, safe? Expert authority interpretation
You have to apologize if you get involved in the funny shop?
合并表格行---三层for循环遍历数据
Protective bearish strategy
What is the optimization method of transaction and database
leetcdoe-342. 4的幂
Shell basic concepts and variables
Mysql中DQL基本练习
朋友发来几个面试题
Dry goods -- encapsulated anti shake and throttling method in the project
微信小程序中自定义模板
Margin calculation
[报错]使用ssh登陆到另一台机器后,发现主机名还是自己|无法访问yarn8088
Guide for using IP phone system and VoIP system
C语言:随机生成数+归并排序