# include<iostream>
# include<queue>
# include<string>
# include<ctime>
using namespace std;
class Person
{
public:
Person(int age, string name)
{
this->m_Age = age;
this->m_Name = name;
}
int m_Age;
string m_Name;
};
void setPersonInf(queue<Person> &p)
{
string name = "abcde";
int age;
for (int i = 0; i < 5; i++)
{
string a = "平民";
a += name[i];
int b = rand() % 100;
Person p1(b,a);
p.push(p1);
}
}
void test02()
{
queue<Person> q;
setPersonInf(q);
while (!q.empty())
{
cout << "队尾元素为:" << endl;
cout << "姓名:" << q.back().m_Name << "年龄:" << q.back().m_Age << endl;
cout << "队头元素为:" << endl;
cout << "姓名:" << q.front().m_Name << "年龄:" << q.front().m_Age << endl;
q.pop();
}
}
void test01()
{
queue<int>q;
q.push(10);
q.push(20);
q.push(30);
q.push(40);
while ((!q.empty()))
{
cout << "队头元素为:" << q.front() << endl;
cout << "队尾元素为:" << q.back() << endl;
//q.pop();
q.pop();
}
cout << "stack的大小" << q.size() << endl;
}
int main()
{
test02();
system("pause");
return 0;
}