调整数组顺序使得奇数在偶数前面

    xiaoxiao2025-04-24  14

    #include <stdio.h> #include <stdlib.h> #include <string.h> void RecorderOddEvent(int *pData,unsigned int length){ if(pData == NULL||length == 0)return ; int *pstart = pData;//指向头 int *pend = pData + length - 1;//指向尾巴 while(pstart < pend){ //向后移动pstart while(pstart<pend&&(*pstart)&0x1 != 0)//找偶数 pstart++; while(pstart<end&&(*pend)&0x1 == 0)//找奇数 pend--; if(pstart<pend){//交换 int tmp= *pstart; *start = *pend; *pend = tmp; } } }
    转载请注明原文地址: https://ju.6miu.com/read-1298403.html
    最新回复(0)