惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
B
Blog
博客园 - Franky
H
Help Net Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
月光博客
月光博客
云风的 BLOG
云风的 BLOG
小众软件
小众软件
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 聂微东
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
M
MIT News - Artificial intelligence
罗磊的独立博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
宝玉的分享
宝玉的分享
L
LangChain Blog
阮一峰的网络日志
阮一峰的网络日志
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Vercel News
Vercel News
V
V2EX
Martin Fowler
Martin Fowler
T
Tailwind CSS Blog
有赞技术团队
有赞技术团队

博客园 - HonestMan

面试百问 o,1的感悟 公司内部推荐 debain oracle insert method a linked list, find the node that the last node point to. Get balance noe Memory - HonestMan - 博客园 ShuffleMerge---microsoft's interview question 新手开始学习linux print all Permutation of a string Google, hire me How to interview a programmer? Binary search tree convert to double linked list. Search in Binary tree spilt a list wirte a function for counting a linked list length Remove repeat char from a string
An funy question!
HonestMan · 2007-09-21 · via 博客园 - HonestMan

Q: An int array, devide an array of integers into two parts, odd in the first part, and even in the second part.

We need some sub Function:
1: IsEven(int n) // n is Even or not
2: void Reorder(int *pData, unsigned int length, bool (*func)(int));

void Reorder(int *pData, unsigned int length, bool (*func)(int))
{
    if (Null==pData || length==0)
        return;
    //
    int *Pbegin = pData;
    int *Pend = pdata+length-1;
    //
    while(Pbegin<Pend)
    {
        if(!func(*Pbegin))
        {
            Pbegin++;
            continue;
        }
        //
        if(func(*Pend))
        {
            Pend--;
            continue;
        }
        //Swap
        int temp;
        temp = * Pbegin;
        *Pbegin = *Pend;
        *Pend = temp;
    }    

}

bool IsEven(int n)
{
    return(n&1)==0;
}

void ReorderOddEven(int *pData, unsigned int length)
{
      Reorder(pData, length, isEven);
}