/*
* Copyright (c) 2006 All rights reserved.
* 文件名:Queue.cpp
*
* 文件标识:Queue
* 摘要:容器适配器Queue编程示例
* 输入:无
* 输出:输出各个队列对象的信息
*
* 当前版本 0.01
* 作者:罗
* 完成日期:2006年4月5日
*/
#include
#include
#include
#include
#include
#include
using namespace std;
struct employee
{
//Member Function
public:
employee() {} //默认构造函数
employee(long eID, string e_Name, float e_Salary);
//Attribute
public:
long ID; //Employee ID
string name; //Employee Name
float salary; //Employee Salary
};
//员工类构造函数
employee::employee(long eID, string e_Name, float e_Salary)
: ID(eID), name(e_Name), salary(e_Salary) {}
//定义一个元素类型为employee、用Deque容器维护被控序列的队列类型
typedef queue > > D_EMPLOYEE_QUEUE;
//定义一个元素类型为employee、用List容器维护被控序列的队列类型
typedef queue > > L_EMPLOYEE_QUEUE;
int main(int argc, char* argv[])
{
D_EMPLOYEE_QUEUE d_employee;
L_EMPLOYEE_QUEUE l_employee;
employee temp;
//下面的三条语句分别构造三个employee对象,然后入容器对象为Deque的队列
d_employee.push(D_EMPLOYEE_QUEUE::value_type(101, "unknown", 20000));
d_employee.push(D_EMPLOYEE_QUEUE::value_type(100, "huahua", 200000));
d_employee.push(D_EMPLOYEE_QUEUE::value_type(101, "jiafeng", 8000));
assert(!d_employee.empty());
//下面这条语句删除队列的第一个employee对象,也就是名字为"unknown"的那个
d_employee.pop();
//输出容器对象为Deque的队列的第一个employee元素
temp = d_employee.front();
cout << temp.ID << '\t' << temp.name << '\t' << temp.salary << endl;
//输出容器对象为Deque的队列的最后一个employee元素
temp = d_employee.back();
cout << temp.ID << '\t' << temp.name << '\t' << temp.salary << endl;
//下面的二条语句分别构造二个employee对象,然后入容器对象为List的队列
l_employee.push(L_EMPLOYEE_QUEUE::value_type(100, "huahua", 200000));
l_employee.push(L_EMPLOYEE_QUEUE::value_type(101, "jiafeng", 8000));
cout << "容器对象为Deque的队列是否为空? " << (d_employee.empty() ? "TRUE" : "FALSE") << endl;
cout << "容器对象为Deque的队列共有" << d_employee.size() << "个employee对象!" << endl;
cout << "容器对象为List的队列是否为空?" << (l_employee.empty() ? "TRUE" : "FALSE") << endl;
cout << "容器对象为List的队列共有" << l_employee.size() << "个employee对象!" << endl;
return 0;
}
|
文件: |
queue.rar |
大小: |
1KB |
下载: |
下载 | |
阅读(1789) | 评论(0) | 转发(0) |