// 2016_3_Aarry.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#define SIZE 10
void Reverse(int* arr,int len)
{
int i=0,j=len-1,temp;
while (i<j)
{
while (i<j&&arr[i]%2==1)
{
i++;
}
while(i<j&&arr[j]%2==0)
{
j--;
}
if (i<j)
{
temp=arr[j];
arr[j]=arr[i];
arr[i]=temp;
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int a[SIZE]={0},i;
for(i=0;i<SIZE;i++)
scanf("%d",&a[i]);
Reverse(a,SIZE);
for(i=0;i<SIZE;i++)
printf("%-5d",a[i]);
printf("\n");
int a11=0;
return 0;
}
将数组中所有奇数移动到所有偶数之前的算法
最新推荐文章于 2025-10-26 16:01:49 发布
本文介绍了一种C语言实现的算法,该算法可以将数组中的所有奇数元素移动到所有偶数元素之前,保持原有顺序不变。通过对数组遍历和临时变量辅助,实现了数字奇偶性划分,适用于数据结构和算法的学习。
1418

被折叠的 条评论
为什么被折叠?



