当前位置:网站首页>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 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("==========排序前的序列=============\n");
initArr(arr,MAXSIZE);
showArr(arr,MAXSIZE);
printf("==========单链表形式的快速排序的序列=============\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)
{
//顺序存储结构的快速排序
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);
}
边栏推荐
- 少儿编程 电子学会图形化编程等级考试Scratch二级真题解析(判断题)2022年6月
- Leetcode-190. inverting binary bits
- One track education, PHP training, unity of knowledge and practice, popular
- 管理区解耦架构见过吗?能帮客户搞定大难题的
- Have you seen the management area decoupling architecture? Can help customers solve big problems
- 半波整流点亮LED
- MySQL practice -- master-slave replication
- Chapter 6 promotion
- LeetCode·每日一题·1331.数组序号转换·离散化
- gicv3 spi register
猜你喜欢

Jenkins -- continuous integration server

Map tiles: detailed explanation of vector tiles and grid tiles

火山石投资章苏阳:硬科技,下一个10年相对确定的答案

Aragon创建DAO polygon BSC测试网

Beyond Istio OSS——Istio服务网格的现状与未来

ES6 null merge operator (?)

LeetCode·每日一题·1331.数组序号转换·离散化

MySQL 实践篇 —— 主从复制

How much do you know about JVM memory management

Gamestop bear market entered NFT trading, and established game retailers took advantage of Web3 to make a second spring
随机推荐
MySQL practice -- master-slave replication
Chinese translation of pointnet:deep learning on point sets for 3D classification and segmentation
基于深度学习的超分辨率重建
半波整流点亮LED
[embedded C foundation] Part 9: basic usage of C language pointer
Redis —— 基础篇
Leetcode-190. inverting binary bits
Using auto.js to realize fifaol3 brush teaching assistant
One track education, PHP training, unity of knowledge and practice, popular
Original juice multifunctional Juicer touch chip-dlt8t02s-jericho
为什么说Crypto游戏正在改变游戏产业?
org.apache.ibatis.exceptions.TooManyResultsException的异常排查过程
Protective bearish strategy
少儿编程 电子学会图形化编程等级考试Scratch二级真题解析(判断题)2022年6月
[FPGA]: AD sampling problem
无法连接服务器怎么办(原始服务器找不到目标资源)
【黑马早报】字节估值缩水,降至2700亿美元;“二舅”视频作者回应抄袭;任泽平称取消商品房预售制是大势所趋;美联储宣布再加息75个基点...
Chapter 6 promotion
[embedded C foundation] Part 7: detailed introduction to C language process control
2020jenkins study notes