本文整理汇总了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:
//.........这里部分代码省略.........