当前位置:网站首页>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);
}
边栏推荐
- Aragon creates Dao polygon BSC test network
- 我抄底了被清算的NFT,却被OpenSea上了锁
- LeetCode·每日一题·1331.数组序号转换·离散化
- Rust from introduction to mastery 01 introduction
- leetcdoe-342. 4的幂
- 如何配置adb环境变量(环境变量在哪打开)
- FFT wave simulation
- IP电话系统和VoIP系统使用指南
- Cesium pit -- pit used by various API calls and API itself
- Android engineers, how to use kotlin to provide productivity?
猜你喜欢
![[embedded C foundation] Part 6: super detailed explanation of common input and output functions](/img/eb/69264bc0d8e9349991b7b9e1b8ca22.png)
[embedded C foundation] Part 6: super detailed explanation of common input and output functions

Leetcode-136. numbers that appear only once

Chapter 6 提升

Rust 从入门到精通01-简介

Using auto.js to realize the function of fifaol3 mobile terminal card interceptor

Smart touch screen LCD bathroom mirror light touch chip-dlt8t02s-jericho

gicv3 spi register
![[matlab] IIR filter](/img/60/8e666bff3d458cdd9367ca45112b92.png)
[matlab] IIR filter

Form for real-time custom verification

GO语言-栈的应用-表达式求值
随机推荐
[FPGA]: ISE generates MCS file and burning process
Guide for using IP phone system and VoIP system
验证码暴力破解测试[通俗易懂]
LyScript 获取上一条与下一条指令
leetcdoe-342. 4的幂
Chapter 6 提升
【黑马早报】字节估值缩水,降至2700亿美元;“二舅”视频作者回应抄袭;任泽平称取消商品房预售制是大势所趋;美联储宣布再加息75个基点...
[FPGA]: ise and Modelsim joint simulation
拥有游戏的一部分,写在我的世界禁用NFT之后
Le transaction
C语言学生成绩管理系统详解[通俗易懂]
基于神经网络的帧内预测和变换核选择
.net for subtraction, intersection and union of complex type sets
Complete set of SSM framework online bookstore
gicv3 spi register
Sub thread update UI full solution
Leetcode · daily question · 1331. array sequence number conversion · discretization
Jar package
Original juice multifunctional Juicer touch chip-dlt8t02s-jericho
Rust 从入门到精通01-简介