implement stack using stack.h headerfile functions

Answer Posted / sv

#include <iostream>
#include <stack>

using namespace std;

int main()
{
string title;
int howmany;


stack<string> discs;
//Asking the user how many discs he wants to enter in the
stack.
//The loop will rotate that many number of times and then
//prompt the user for input.
cout<<"How many discs :";
cin>>howmany;

for(int i=0;i>title;
//pushing the discs one upon the other
discs.push(title);
}

cout<<"Now at the top of the CD Stack we have :"<<discs.top
()<<endl;
cout<<"The first one entered is "<<endl;
while(!discs.empty())
{
title = discs.top();
discs.pop();
}
cout<<title<<endl;
return 0;
}

Is This Answer Correct ?    4 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the need of a destructor?

619


What is a static element?

563


Why can templates only be implemented in the header file?

641


What are the types of pointer?

533


How do you find out if a linked-list has an end? (I.e. The list is not a cycle)

588






What is c++ library?

584


What is the extraction operator and what does it do?

598


If you push the numbers (in order) 1, 3, and 5 onto a stack, which pops out first a) 1 b) 5 c) 3

809


How do you instruct your compiler to print the contents of the intermediate file showing the effects of the preprocessor?

570


Which of the following is evaluated first: a) && b) || c) !

1783


What is the use of pointer in c++ with example?

551


Are vectors passed by reference c++?

501


What are the differences between new and malloc?

621


What are the c++ access specifiers?

752


What happens when the extern "c" char func (char*,waste) executes?

623