当前位置:网站首页>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);
}
边栏推荐
- Redis - Basics
- [dark horse morning post] byte valuation has shrunk to $270billion; "Second uncle" video author responded to plagiarism; Renzeping said that the abolition of the pre-sale system of commercial housing
- [ecmascript6] function and its related use
- 合并表格行---三层for循环遍历数据
- Paddleclas classification practice record
- Leetcode-136. numbers that appear only once
- Extended operator
- 什么叫杂谈(e网杂谈)
- Array, string de duplication
- kotlin学习笔记3——Lambda编程
猜你喜欢

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

倒计时 2 天!2022 中国算力大会:移动云邀您共见算力网络,创新发展

Fast classification of array.group() in ES6

Tidb 6.x in action was released, a summary of 6.x practices that condense the collective wisdom of the community!

gicv3 spi register

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

Half wave rectification light LED

一根筋教育PHP培训 知行合一收热捧

Black Scholes Merton European option pricing formula

Auto.js enables Taobao to quickly submit orders
随机推荐
powerdesigner创建数据库模型(概念模型举例)
paddleClas分类实践记录
【黑马早报】字节估值缩水,降至2700亿美元;“二舅”视频作者回应抄袭;任泽平称取消商品房预售制是大势所趋;美联储宣布再加息75个基点...
Guide for using IP phone system and VoIP system
剖析 kubernetes 集群内部 DNS 解析原理
9、 Kubernetes configuration and storage
How much do you know about JVM memory management
Leetcode-190. inverting binary bits
无法连接服务器怎么办(原始服务器找不到目标资源)
Rust from introduction to mastery 01 introduction
蓝桥集训(附加面试题)第七天
Paddleclas classification practice record
Debezium系列之:2.0.0.Beta1的重大变化和新特性
如何配置adb环境变量(环境变量在哪打开)
火山石投资章苏阳:硬科技,下一个10年相对确定的答案
Cesium pit -- pit used by various API calls and API itself
10、 Kubernetes scheduling principle
org.apache.ibatis.exceptions.TooManyResultsException的异常排查过程
[error] after logging in to another machine using SSH, you find that the hostname is still yourself | unable to access yarn8088
nport串口服务器配置网址(串口服务器是不是网口转串口)