Пример #1
0
void play()
{
    Student s1, s2, s3;
    s1.age = 21;
    s2.age = 22;
    s3.age = 23;

    LinkStack<Student> ls; // ´´½¨Õ»

    // ÈëÕ»
    ls.push(s1);
    ls.push(s2);
    ls.push(s3);

    // »ñÈ¡Õ»¶¥ÔªËØ
    Student tmp;
    ls.top(tmp);
    cout << "top of stack: " << tmp.age << endl;
    cout << "size of stack: " << ls.size() << endl;

    // ³öÕ»
    while (ls.size() > 0) {
        ls.pop(tmp);
    }

    ls.clear();

}
Пример #2
0
int main()
{
	char item;
	//STL实现
	//stack<char> numbers;
	//自己写的LinkStack模板类
	LinkStack<char> numbers;
	cout << "Please enter the string sequence.\nIf you want to quit, Please enter #\n";
	item = cin.get();
	while (item != '#')
	{
		numbers.push(item);
		item = cin.get();
	}
	cout << endl;
	while (!numbers.empty()) {
		cout << numbers.top();
		numbers.pop();
	}
	cout << endl;
}