//调整数组使奇数全部都位于偶数前面。
//输入一个整数数组。实现一个函数,来调整该数组中数字的顺序使得数组中全部的奇数位于数组的前半部分,全部偶数位于数组的后半部分
#include <stdio.h>
void Adjust(int *arr, int len)
{
int *start = arr;
int *end = arr + len - 1;
while (start < end)
{
int temp;
while((*start&1)==1)
{
start++;
}
while((*end& 1) == 0)
{
end--;
}
if (start<end)
{
temp = *start;
*start = *end;
*end = temp;
start++;
end--;
}
}
}
int main()
{
int i;
int arr[] = { 1,8, 3,2, 5, 7, 9, 4, 6, 11 };
Adjust(arr, sizeof(arr) / sizeof(arr[0]));
for (i = 0; i < sizeof(arr) / sizeof(arr[0]); i++)
{
printf("%3d", arr[i]);
}
printf("\n");
return 0;
}

最新文章

  1. Function.prototype.toString 的使用技巧
  2. Doc转文本
  3. document对象补充
  4. ecstore2.0数据库词典
  5. bzoj1043
  6. 初始seajs
  7. 深入Redux架构
  8. CSAcademy Beta Round #5 Force Graph
  9. springboot 入门二- 读取配置信息一
  10. .Net Core MongoDB 简单操作。
  11. 关于惠普hp服务器开机时F10菜单变成F10 Function Disabled的解决方法
  12. window.open 打开子窗口,关闭所有的子窗口
  13. jquery监测文本框变化
  14. Android APK代码混淆与资源混淆详解,你确定不看?
  15. msf客户端渗透(十):社会工程学
  16. 使用Apache Bench对网站性能进行测试
  17. ZT 内地20年经典电视剧大全
  18. python多线程为什么不能利用多核cpu
  19. 微服务架构之spring cloud turbine
  20. python学习(二十二) Python 中boolean

热门文章

  1. Immediately-Invoked Puzzler
  2. 4. Add override methods to class
  3. Hive Python Streaming的原理及写法
  4. Linux学习笔记--which命令(搜索命令的命令)
  5. Visual Studio 2008破解90天试用期
  6. 【CSWS2014 Main Conference】Some Posters
  7. memcached 下载安装
  8. oracle默认连接数150
  9. 微信小程序开发思路
  10. 【mysql+RBAC】RBAC权限处理(转载:http://www.cnblogs.com/xiaoxi/p/5889486.html 平凡希)