【C语言】调整数组使奇数所有都位于偶数前面(改动)
2024-09-14 21:15:26
//调整数组使奇数全部都位于偶数前面。
//输入一个整数数组。实现一个函数,来调整该数组中数字的顺序使得数组中全部的奇数位于数组的前半部分,全部偶数位于数组的后半部分
#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;
}
最新文章
- Function.prototype.toString 的使用技巧
- Doc转文本
- document对象补充
- ecstore2.0数据库词典
- bzoj1043
- 初始seajs
- 深入Redux架构
- CSAcademy Beta Round #5 Force Graph
- springboot 入门二- 读取配置信息一
- .Net Core MongoDB 简单操作。
- 关于惠普hp服务器开机时F10菜单变成F10 Function Disabled的解决方法
- window.open 打开子窗口,关闭所有的子窗口
- jquery监测文本框变化
- Android APK代码混淆与资源混淆详解,你确定不看?
- msf客户端渗透(十):社会工程学
- 使用Apache Bench对网站性能进行测试
- ZT 内地20年经典电视剧大全
- python多线程为什么不能利用多核cpu
- 微服务架构之spring cloud turbine
- python学习(二十二) Python 中boolean
热门文章
- Immediately-Invoked Puzzler
- 4. Add override methods to class
- Hive Python Streaming的原理及写法
- Linux学习笔记--which命令(搜索命令的命令)
- Visual Studio 2008破解90天试用期
- 【CSWS2014 Main Conference】Some Posters
- memcached 下载安装
- oracle默认连接数150
- 微信小程序开发思路
- 【mysql+RBAC】RBAC权限处理(转载:http://www.cnblogs.com/xiaoxi/p/5889486.html 平凡希)