当前位置:网站首页>Quick sort code implementation
Quick sort code implementation
2022-07-25 06:17:00 【Can't fail I】
Quick sort

In the following example , Select the last element 40 As a median .i Used to traverse the subscript of the array ;k Representation ratio 40 The subscript of the small element to be saved

int Partition(int* arr, int left, int right) {
int k, i;
for (i = k = left; i < right; i++) {
if (arr[i] < arr[right]) {
swap(arr[k], arr[i]);
k++;
}
}
swap(arr[k], arr[right]);
return k;
}
// Recursive implementation of quick sorting
void QuickSort(ElemType A[], int low, int high) {
if (low < high) {
int pivotpos = Partition(A, low, high);// The elements to the left of the split point are smaller than the split point , The elements on the right of the split point are larger than the split point
QuickSort(A, low, pivotpos - 1);
QuickSort(A, pivotpos + 1, high);
}
}
边栏推荐
- (2022 Niuke multi School II) l-link with level editor I (dynamic planning)
- Promise implementation
- (2022牛客多校二)L-Link with Level Editor I(动态规划)
- “蔚来杯“2022牛客暑期多校训练营2 Link with Game Glitch (spfa找正负环)
- (2022牛客多校)D-Link with Game Glitch(spfa)
- Codeforces Round #809 (Div. 2)
- 【datawhale202207】强化学习:策略梯度和近端策略优化
- Cout format output common functions and flags summary
- MFC IniFile Unicode mode reading method
- 函数模板学习记录
猜你喜欢

【C语言】指针和数组的深入理解(第一期)

Tutorial: encryption keys in cloud (using golang and CLI)

The LAF protocol elephant of defi 2.0 may be one of the few profit-making means in your bear market

剑指 Offer 54. 二叉搜索树的第k大节点

Baidu, Alibaba, Tencent, who fell first?

Ffmpeg notes (I) fundamentals of audio and video

How does vscode enable multiple terminals? How to display horizontally?

Design of automatic machine dot drawing script based on C language

(2022牛客多校二)L-Link with Level Editor I(动态规划)

ROI pooling and ROI align
随机推荐
A little experience about von Mises distribution
Brief tutorial of vbs script syntax (1)
Vbs script COM object extension and use (3)
Data too long for column ‘data‘ at row 1以及设置成longblob造成的乱码解决。node-mysql
VBA common objects
Openzeppelin scalable template library contract initialization details
(2022 Niuke multi school) D-Link with game glitch (SPFA)
Binary search tree (day 75)
深度解析:2022年最火的商业模式链动2+1,是合法模式吗?
Dry goods | training AI model can't find data? Collect 20 selected open source communities!
剑指 Offer 32 - I. 从上到下打印二叉树
In depth analysis: is the hottest business model in 2022 linked by 2+1 a legal model?
target_compile_features specified unknown feature “cxx_std_14“ for target
Design of automatic machine dot drawing script based on C language
(2022 Niuke multi School II) l-link with level editor I (dynamic planning)
[C language] in depth understanding of pointers and arrays (phase I)
(牛客多校二)J-Link with Arithmetic Progression(最小二乘法/三分)
VBS common built-in functions (2)
Use abp Zero builds a third-party login module (III): web side development
It is said that screentogif is a GIF recording artifact, but I don't know that its strength is far from here