标签:
快速排序是冒泡排序的一种优化,用的是分治的想法,每次将其分成两半分别排序
下标
|
0
|
1
|
2
|
3
|
4
|
5
|
数据
|
6
|
2
|
7
|
3
|
8
|
9
|
下标
|
0
|
1
|
2
|
3 |
4
|
5
|
数据
|
3
|
2
|
7
|
6
|
8
|
9
|
下标
|
0
|
1
|
2
|
3
|
4
|
5
|
数据
|
3
|
2
|
6
|
7
|
8
|
9
|
下标
|
0
|
1
|
2
|
3
|
4
|
5
|
数据
|
3
|
2
|
6
|
7
|
8
|
9
|
void QuickSort(struct SQ_LIST *v, int left, int right) { if (left < right) { int key = v->elem[left].ID; int low = left; int high = right; while (low < high) { while (low < high && v->elem[high].ID > key) high--; if (low < high) { v->elem[low].ID = v->elem[high].ID; ++low; } while (low < high && v->elem[low].ID < key) low++; if (low < high) v->elem[high].ID = v->elem[low].ID; --high; } v->elem[low].ID = key; QuickSort(v, left, low - 1); QuickSort(v, low + 1, right); } }
标签:
原文地址:http://www.cnblogs.com/INnoVationv2/p/5503678.html