/*
* Copyright (c) 2006 All rights reserved.
* 文件名:Stack.cpp
*
* 文件标识:Stack
* 摘要:容器适配器Stack编程示例
* 输入:无
* 输出:输出各个栈对象的信息
*
* 当前版本 0.01
* 作者:罗
* 完成日期:2006年4月5日
*/
#include
#include
#include
#include
#include
#include
#include
using namespace std;
struct employee
{
//Member Function
public:
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) {}
//定义一个用Vector维护被控序列的栈类型
typedef stack > > V_EMPLOYEE_STACK;
//定义一个用Deque维护被控序列的栈类型
typedef stack > > D_EMPLOYEE_STACK;
//定义一个用List维护被控序列的栈类型
typedef stack > > L_EMPLOYEE_STACK;
int main(int argc, char* argv[])
{
V_EMPLOYEE_STACK v_employee;
D_EMPLOYEE_STACK d_employee;
L_EMPLOYEE_STACK l_employee;
//下面的三条语句分别构造三个employee对象,然后入容器对象为Vector的栈
v_employee.push(V_EMPLOYEE_STACK::value_type(100, "huahua", 200000));
v_employee.push(V_EMPLOYEE_STACK::value_type(101, "jiafeng", 8000));
v_employee.push(V_EMPLOYEE_STACK::value_type(101, "unknown", 20000));
assert(!v_employee.empty());
//下面这条语句弹出最后入栈的employee对象
v_employee.pop();
//下面的三条语句分别构造三个employee对象,然后入容器对象为Deque的栈
d_employee.push(D_EMPLOYEE_STACK::value_type(100, "huahua", 200000));
d_employee.push(D_EMPLOYEE_STACK::value_type(101, "jiafeng", 8000));
d_employee.push(D_EMPLOYEE_STACK::value_type(101, "unknown", 20000));
assert(!d_employee.empty());
//下面这条语句弹出最后入栈的employee对象
d_employee.pop();
//下面的三条语句分别构造三个employee对象,然后入容器对象为List的栈
l_employee.push(L_EMPLOYEE_STACK::value_type(100, "huahua", 200000));
l_employee.push(L_EMPLOYEE_STACK::value_type(101, "jiafeng", 8000));
l_employee.push(L_EMPLOYEE_STACK::value_type(101, "unknown", 20000));
assert(!l_employee.empty());
//下面这条语句弹出最后入栈的employee对象
l_employee.pop();
cout << "容器对象为Vector的栈是否为空? " << (v_employee.empty() ? "TRUE" : "FALSE") << endl;
cout << "容器对象为Vector的栈共有" << v_employee.size() << "个employee对象!" << endl;
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;
}
|
文件: |
stack.rar |
大小: |
1KB |
下载: |
下载 | |
阅读(1245) | 评论(0) | 转发(0) |