当前位置:网站首页>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);
}
边栏推荐
- Why is crypto game changing the game industry?
- Dimming and color matching cool light touch chip-dlt8ma12ts-jericho
- butterfly spreads
- Cesium pit -- pit used by various API calls and API itself
- Shell basic concepts and variables
- Black cat takes you to learn UFS agreement part 2: Interpretation of UFS related terms
- Single option trading and cross trade
- Gamestop bear market entered NFT trading, and established game retailers took advantage of Web3 to make a second spring
- Vditor 渲染器如何做到服务端渲染(SSR)?
- 屈辱、抗争、逆转,三十年,中国该赢微软一次了
猜你喜欢

Using auto.js to realize fifaol3 brush teaching assistant

With 433 remote control UV lamp touch chip-dlt8sa20a-jericho

RGB game atmosphere light touch chip-dlt8s04a-jericho

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

Aragon创建DAO polygon BSC测试网

Parent and child of treeselect

Machine learning Basics - integrated learning-13

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

Array, string de duplication

GameStop熊市杀入NFT交易,老牌游戏零售商借Web3焕发第二春
随机推荐
Intra prediction and transform kernel selection based on Neural Network
Have you seen the management area decoupling architecture? Can help customers solve big problems
Single option trading and cross trade
Have a part of the game, after NFT is disabled in my world
Jenkins--持续集成服务器
【ECMAScript6】Promise
Redis —— 基础篇
Leetcode 笔记 118. 杨辉三角
Black Scholes Merton European option pricing formula
夜神模拟器抓包微信小程序
Leetcode 笔记 566. 重塑矩阵
2020jenkins study notes
Getderivedstatefromprops lifecycle
为什么说Crypto游戏正在改变游戏产业?
[embedded C foundation] Part 6: super detailed explanation of common input and output functions
Beyond Istio OSS——Istio服务网格的现状与未来
Vditor 渲染器如何做到服务端渲染(SSR)?
Chapter 6 提升
Table list filter results remain unchanged
Definition of option basis