当前位置:网站首页>C language: quick sorting of sequential storage structure
C language: quick sorting of sequential storage structure
2022-07-28 13:36:00 【Nianchi ichthyology programming】
#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 swap(int arr[] , int i , int j);
void quickSort2(int arr[] , int left , int right);
int main()
{
srand((unsigned int)time(NULL));
int arr[MAXSIZE];
printf("========== The sequence before sorting =============\n");
initArr(arr,MAXSIZE);
showArr(arr,MAXSIZE);
printf("========== Quick sort sequence in the form of single linked list =============\n");
quickSort2(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 swap(int arr[] , int i , int j)
{
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
void quickSort2(int arr[] , int left , int right)
{
// Quick sorting of sequential storage structure
if(left>=right){
return;
}
int pivot = arr[left];
int i = left+1;
int j = left+1;
while(j<=right){
if(arr[j] < pivot){
// int temp = arr[i];
// arr[i] = arr[j];
// arr[j] = temp;
swap(arr,i,j);
i++;
}
j++;
}
// int temp1 = arr[left];;
// arr[left] = arr[i-1];
// arr[i-1] = temp1;
swap(arr,left,i-1);
quickSort2(arr,left,i-1);
quickSort2(arr,i,right);
}
边栏推荐
- Rust from introduction to mastery 01 introduction
- 用非递归的方法实现二叉树中的层遍历,先序遍历,中序遍历和后序遍历
- Guide for using IP phone system and VoIP system
- 基于pytorch卷积人脸表情识别–毕业设计「建议收藏」
- [报错]使用ssh登陆到另一台机器后,发现主机名还是自己|无法访问yarn8088
- IP电话系统和VoIP系统使用指南
- Leetcode 笔记 566. 重塑矩阵
- [FPGA] FIR filter - half band filter
- Beyond istio OSS -- current situation and future of istio Service Grid
- gicv3 spi register
猜你喜欢

Gamestop bear market entered NFT trading, and established game retailers took advantage of Web3 to make a second spring

Form for real-time custom verification

Map tiles: detailed explanation of vector tiles and grid tiles

Leetcdoe-342. Power of 4

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

Protective bearish strategy

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

IP电话系统和VoIP系统使用指南

Fast classification of array.group() in ES6

Volcanic stone investment Zhang Suyang: hard technology, the relatively certain answer in the next 10 years
随机推荐
[ecmascript6] function and its related use
【黑马早报】字节估值缩水,降至2700亿美元;“二舅”视频作者回应抄袭;任泽平称取消商品房预售制是大势所趋;美联储宣布再加息75个基点...
什么叫杂谈(e网杂谈)
Rust 从入门到精通01-简介
Compare the new and old data to find the added and deleted ones
Form for real-time custom verification
功率放大器和匹配网络学习
[matlab]: FFT related problems
The form select in antd is received before it is selected
[FPGA]: AD sampling problem
Unity - "synthetic watermelon" small game notes
Le transaction
C语言:随机生成数+快速排序
少儿编程 电子学会图形化编程等级考试Scratch二级真题解析(判断题)2022年6月
沾上趣店,都得道歉?
Kotlin learning notes 3 - lambda programming
[ecmascript6] symbol and its related use
Volcanic stone investment Zhang Suyang: hard technology, the relatively certain answer in the next 10 years
Array, string de duplication
Leetcode 笔记 566. 重塑矩阵