当前位置:网站首页>C语言:随机生成数+快速排序
C语言:随机生成数+快速排序
2022-07-28 12:18:00 【念迟鱼学编程】
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define MAXSIZE 10
void initArr(int arr[] , int length);
void showArr(int arr[] , int length);
void quickSort(int arr[] , int left , int right);
int main()
{
srand((unsigned int)time(NULL));
int arr[MAXSIZE];
printf("==========排序前的序列=============\n");
initArr(arr,MAXSIZE);
showArr(arr,MAXSIZE);
printf("==========快速排序后的序列=============\n");
quickSort(arr,0,MAXSIZE-1);
showArr(arr,MAXSIZE);
system("pause");
return 0;
}
void initArr(int arr[] , int length)
{
for(int i = 0 ; i < length ; i++){
arr[i] = rand()%20;
}
}
void showArr(int arr[] , int length)
{
for(int i = 0 ; i < length ; i++){
printf("%4d",arr[i]);
}
printf("\n");
}
void quickSort(int arr[] , int left , int right)
{
//快速排序
if(left>right){
return;
}
int i = left;
int j = right;
int pivot = arr[i];
while(i<j){
while(i<j && arr[j] >= pivot){
j--;
}
arr[i] = arr[j];
while(i<j && arr[i] <= pivot){
i++;
}
arr[j] = arr[i];
}
arr[i] = pivot;
quickSort(arr,left,i-1);
quickSort(arr,i+1,right);
}
边栏推荐
- Form for real-time custom verification
- Why neural networks are ineffective?
- Aragon创建DAO polygon BSC测试网
- [FPGA] joint simulation of vivado and Modelsim
- Auto.js enables Taobao to quickly submit orders
- Complete set of SSM framework online bookstore
- Definition of option basis
- Dry goods -- encapsulated anti shake and throttling method in the project
- [embedded C foundation] Part 5: original code / inverse code / complement code
- Getderivedstatefromprops lifecycle
猜你喜欢

PCP parity principle arbitrage

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

Using auto.js to realize fifaol3 brush teaching assistant

Led aquarium lamp touch chip-dlt8t02s-jericho

Leetcdoe-342. Power of 4

Chinese translation of pointnet:deep learning on point sets for 3D classification and segmentation

Is jetpack compose completely out of view?

拥有游戏的一部分,写在我的世界禁用NFT之后

Jenkins -- continuous integration server

Protective bearish strategy
随机推荐
功率放大器和匹配网络学习
【黑马早报】字节估值缩水,降至2700亿美元;“二舅”视频作者回应抄袭;任泽平称取消商品房预售制是大势所趋;美联储宣布再加息75个基点...
Is jetpack compose completely out of view?
.NET的求复杂类型集合的差集、交集、并集
[FPGA]: MATLAB generates COE files
Black Scholes Merton European option pricing formula
RGB game atmosphere light touch chip-dlt8s04a-jericho
验证码暴力破解测试[通俗易懂]
Protective bearish strategy
leetcode-190.颠倒二进制位
Smart touch screen LCD bathroom mirror light touch chip-dlt8t02s-jericho
Kotlin learning notes 3 - lambda programming
Have you seen the management area decoupling architecture? Can help customers solve big problems
夜神模拟器抓包微信小程序
Using auto.js to realize fifaol3 brush teaching assistant
powerdesigner创建数据库模型(概念模型举例)
基于神经网络的帧内预测和变换核选择
Redis —— 基础篇
2020jenkins study notes
MySQL practice -- master-slave replication