#include <iostream>
#include <string>
using namespace std;
struct Infor
{
char szSex;
string strName;
struct Infor *next;
};
class Test
{
public:
Test();
void InterFace();
void CreatQuene();
void ShowResult();
private:
int m_nMen;
int m_nFamle;
struct Infor *m_pHeadMen, *m_pTailMen;
struct Infor *m_pHeadFamle, *m_pTailFamle;
};
Test::Test()
{
m_nMen = m_nFamle = 0;
m_pHeadMen = m_pTailMen = new struct Infor;
m_pHeadFamle = m_pTailFamle = new struct Infor;
}
void Test::CreatQuene()
{
struct Infor *p = NULL;
char szSex;
string strName;
while (1)
{
cin >> szSex;
if (szSex == ‘m’)
{
cin >> strName;
p = new struct Infor;
p->strName = strName;
p->szSex = szSex;
m_pTailMen->next = p;
m_pTailMen = p;
p->next = NULL;
m_nMen++;
}
else if (szSex == ‘f’)
{
cin >> strName;
p = new struct Infor;
p->strName = strName;
p->szSex = szSex;
m_pTailFamle->next = p;
m_pTailFamle = p;
p->next = NULL;
m_nFamle++;
}
else
{
break;
}
}
}
void Test::ShowResult()
{
struct Infor *pMen = NULL, *pFamle = NULL;
pMen = m_pHeadMen->next;
pFamle = m_pHeadFamle->next;
cout << “Boy students Girl students” << endl;
while (NULL != pMen && NULL != pFamle)
{
cout << pMen->strName << ” ” << pFamle->strName << endl;
pMen = pMen->next;
pFamle = pFamle->next;
m_nMen–;
m_nFamle–;
}
if (0 != m_nMen)
{
cout << m_nMen << ” Boy students waitting,the first one is ”
<< pMen->strName << endl;
}
else if (0 != m_nFamle)
{
cout << m_nFamle << ” Girl students waitting, the first one is ”
<< pFamle->strName << endl;
}
else
{
cout << “Nobody Waitting” << endl;
}
}
void Test::InterFace()
{
char choice;
cin >> choice;
while (choice != ‘Q’)
{
if (‘P’ == choice)
{
ShowResult();
}
else
{
CreatQuene();
}
cin >> choice;
}
}
int main()
{
freopen(“1.txt”, “r”, stdin);
Test t1;
t1.InterFace();
getchar();
return 0;
}