非递归快速排序c语言
时间: 2023-10-17 14:26:29 浏览: 103
非递归快速排序
4星 · 用户满意度95%
非递归快速排序的C语言实现如下:
```c
#include <stdio.h>
void swap(int* a, int* b) {
int temp = *a;
*a = *b;
*b = temp;
}
int partition(int arr[], int low, int high) {
int pivot = arr < pivot) {
i++;
swap(&arr[i], &arr[j]);
}
}
swap(&arr[i + 1], &arr = low;
stack[++top = high;
while (top >= 0) {
high = stack[top--];
low = stack[top--];
int pi = partition(arr, low, high);
if (pi - 1 > low) {
stack[++top = low;
stack[++top = pi - 1;
}
if (pi + 1 < high) {
stack[++top = pi + 1;
stack[++top = high;
}
}
}
int main() {
int arr[] = {9, 2, 7, 4, 5, 1, 6, 3, 8};
int n = sizeof(arr) / sizeof(arr<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [快速排序(非递归)——C语言实现](https://blog.csdn.net/qq_41890240/article/details/124110735)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [快速排序(递归与非递归)c语言实现](https://blog.csdn.net/qq_52496633/article/details/122942504)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文