c++链表问题,关于如何拆分链表,急!

题目:请完成函数twoQueue()。
------------------------
函数twoQueue()的功能是根据学生性别,将学生链表拆分成女生链表girls和男生链表boys。

注意:仅在标有"Program"和"End"的注释行之间补充填写代码。
请勿改动主函数main和其它任何已有内容。
---------------------------------------------------------*/


/*------------------------------------------------------
【程序设计】
--------------------------------------------------------

题目:请完成函数twoQueue()。
    ------------------------
    函数twoQueue()的功能是根据学生性别,将学生链表拆分成女生链表girls和男生链表boys。
--------------------------------------------------------
注意:仅在标有"Program"和"End"的注释行之间补充填写代码。
      请勿改动主函数main和其它任何已有内容。
---------------------------------------------------------*/


#include <iostream>
#include <ctime>
using namespace std;
struct student {
    int id;
    char gender;
    student* next;
};

void twoQueue(student* hybrid, student*& girls, student*& boys);
void output(student* girls, student* boys);
int main()
{
    srand(time(NULL));
    int num;
    //cin >> num;
    num = rand() % 10;
    cout << num << endl;
    student* hybrid=NULL, *hybridCur = NULL, *tmp;
    for (int i = 0; i < num; i++)
    {
        tmp = new student;
        //cin >> tmp->id >> tmp->gender;
        tmp->id = i;
        tmp->gender = rand() % 2 ? 'M' : 'F';
        cout << tmp->id << " " << tmp->gender << endl;
        tmp->next = NULL;
        if (hybridCur == NULL) {
            hybridCur = tmp;
            hybrid = hybridCur;
        }
        else {
            hybridCur->next = tmp;
            hybridCur = hybridCur->next;
        }
    }
    student* girls = NULL, * boys = NULL;
    twoQueue(hybrid, girls, boys);

    output(girls, boys);
}

void twoQueue(student* hybrid, student*& girls, student*& boys) {
    
    /**********Program**********/







    /**********  End  **********/
}

void output(student* girls, student* boys) {
    while (girls && girls->next)
    {
        cout << girls->id << ",";
        girls = girls->next;
    }
    if (girls)
        cout << girls->id << ";";
    while (boys && boys->next)
    {
        cout << boys->id << ",";
        boys = boys->next;
    }
    if (boys)
        cout << boys->id << endl;
}




补充如下,如有帮助,请帮忙采纳一下,谢谢。

void twoQueue(student* hybrid, student*& girls, student*& boys) {
    /**********Program**********/
    
    student* pg,*pb;
    girls = 0;
    boys = 0;
    pg = 0;pb = 0;
    while(hybrid)
    {
        if(hybrid->gender=='F')
        {
            if(girls == 0)
            {
                girls = hybrid;
                pg = girls;
            }
            else
            {
                pg->next = hybrid;
                pg = hybrid;
            }
        }
        else
        {
            if (boys == NULL)
            {
                boys = hybrid;
                pb = boys;
            }else
            {
                pb->next = hybrid;
                pb = hybrid;
            }
        }
        hybrid = hybrid->next;
        
    }
    if(pg) pg->next = NULL;
    if(pb) pb->next = NULL;
 
    /**********  End  **********/
}