首页 > 编程语言 > 详细

基于快排思想实数组现将数组中所有奇数放到偶数前面

时间:2019-07-16 20:41:57      阅读:84      评论:0      收藏:0      [点我收藏+]
 1 #include <stdio.h>
 2 
 3 void sort(int sz[], int low, int high)
 4 {
 5     int p = sz[low]; // 模仿快速排序,时间复杂度为o(n), 空间复杂度o(1)
 6     while (low < high)
 7     {
 8         while (low < high && (sz[high] % 2 == 0))
 9             high--;
10         sz[low] = sz[high];
11         while (low < high && (sz[low] % 2 != 0))
12             low++;
13         sz[high] = sz[low];
14     }
15     sz[low] = p;
16 }
17 
18 int main()
19 {
20     int sz[] = {18, 9, 71, 72, 99, 90, 64, 3, 22, 55, 10, 11};
21     sort(sz, 0, 11);
22     for (int i = 0; i < 12; i++)
23         printf("%d ", sz[i]);
24     return 0;
25 }

 

基于快排思想实数组现将数组中所有奇数放到偶数前面

原文:https://www.cnblogs.com/sqdtss/p/11197318.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!