当前位置: 首页>>代码示例>>C++>>正文


C++ LinkedStack::displayStack方法代码示例

本文整理汇总了C++中LinkedStack::displayStack方法的典型用法代码示例。如果您正苦于以下问题:C++ LinkedStack::displayStack方法的具体用法?C++ LinkedStack::displayStack怎么用?C++ LinkedStack::displayStack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LinkedStack的用法示例。


在下文中一共展示了LinkedStack::displayStack方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
    bool stay = true;

    // create one instance for each of the test classes

    cout << "\nInstanciate an object of LinkedStack\n";
    LinkedStack<string>* stackPtr = new LinkedStack<string>();

    cout << "\nProgram started, \n"
         << "    initiate the TEST DRIVER with a set of hard-wired data!\n"
         << "For example, \n"
         << "    you may use this set of tokens as a default test case: \n"
         << "    the, items, are, 123, 456, 789, and, abc";

    string choice; // user input for choices

    // initialize the LinkedStack class instances
    stackPtr->push("the");
    stackPtr->push("items");
    stackPtr->push("are");
    stackPtr->push("123");
    stackPtr->push("456");
    stackPtr->push("789");
    stackPtr->push("and");
    stackPtr->push("abc");
    cout << "\n   Use the P - peek command to view the stack.\n";

    // main menu while
    while(stay) {  // main menu while starts
        menu();
        stay = true;
        cin >> choice;
        cin.ignore();

        if(choice.size() == 1) {
            char ch = choice[0];
            vector<string> dump;
            string value;
            switch(ch) {  // main menu switch starts

            case 'd': // display stack
            case 'D':
                if(stackPtr->isEmpty()) {
                    cout << "\n		Stack is empty.\n";
                } else {
                    stackPtr->displayStack();
                }
                break;

            case 'e': // is stack empty?
            case 'E':
                if(stackPtr->isEmpty())
                {
                    cout << "\n		The list is empty\n";
                } else {
                    cout << "\n		There are items in the stack\n";
                }
                break;

            case 'i': // insert item
            case 'I':
                cout << "		insert item: ";
                cin >> value;
                stackPtr->push(value);
                break;

            case 'r': // remove item
            case 'R':
                if(stackPtr->isEmpty())
                {
                    cout << "\n		The list is empty\n";
                } else {
                    stackPtr->pop();
                    cout << "\n		Top item removed.\n";
                }
                break;

            case 'c': // clear stack
            case 'C':
                // to be completed by you;
                if(stackPtr->isEmpty()) {
                    cout << "\n		Stack already empty.\n";
                } else {
                    stackPtr->clear();
                }

                break;

            case 'p': // peek TOP value
            case 'P':
                cout << "\n		The top value is: " << stackPtr->peek() << endl;
                break;

            case 'q': // quit main menu
            case 'Q':
                stay = false;
                break;

            default:
//.........这里部分代码省略.........
开发者ID:Genjutsu,项目名称:Labs,代码行数:101,代码来源:lab2.cpp


注:本文中的LinkedStack::displayStack方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。