#include <stdio.h> void oddAheadOfEven(int array[],int start,int end) { int lastOddIndex = start-1; for(int index=start;index<=end;index++) { if(array[index]&0x01) { lastOddIndex++; int temp = array[lastOddIndex]; array[lastOddIndex] = array[index]; array[index] = temp; } } } void printArray(int array[],int numsSize) { printf("\nprintf Array begin---------------------\n"); for(int index =0;index<numsSize;index++) { printf(" %d \t",array[index]); } printf("\nprintf Array end-----------------------\n"); } void test() { int array[] = {1,32,3,542,21,5,2,6,56,4,6,7,2}; int numsSize = sizeof(array)/sizeof(int); printArray(array,numsSize); oddAheadOfEven(array,0,numsSize-1); printArray(array,numsSize); } int main(void) { // your code goes here test(); return 0; }
http://ideone.com/mnYx0V
时间: 2024-10-10 13:44:25