ministack.cpp

来自「数据结构大作业:miniStack类的设计」· C++ 代码 · 共 52 行

CPP
52
字号
// miniStack.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "l_stack.h"


/*
filename: stack_test.cpp
usage: 测试l_stack.h的实现 
*/

#include <iostream>
#include "l_stack.h"
using namespace std;

int main()
{
    miniStack<int> st;
    
    st.push(1);
    st.push(2);
    st.push(3);
    
    cout << st.top() << ' ';
    st.pop();
    
    cout << st.top() << ' ';
    st.pop();
    
    //modify top elements
    st.top() = 4;
    
    //push two new elements
    st.push(5);
    st.push(6);
    
    //pop one elements without processing it
    st.pop();
    
    //pop and print remaining elements
    while (!st.empty()) {
      cout << st.top() << ' ';
      st.pop();
    }
    cout << endl;
}
/*
程序输出如下:
3 2 5 4 
*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?