implement stack using stack.h headerfile functions



implement stack using stack.h headerfile functions..

Answer / 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

More C++ General Interview Questions

Is c++ an oop?

0 Answers  


What is c++ iterator?

0 Answers  


What kind of jobs can I get with c++?

0 Answers  


Can the operator == be overloaded for comparing two arrays consisting of characters by using string comparison?

0 Answers  


How can an improvement in the quality of software be done by try/catch/throw?

0 Answers  


Explain rtti.

0 Answers  


wrong statement about c++ a)code removably b)encapsulation of data and code c)program easy maintenance d)program runs faster

11 Answers  


Write a struct time where integer m, h, s are its members?

0 Answers  


What is the latest version on c++?

0 Answers  


Write a program which uses functions like strcmp(), strcpy()? etc

0 Answers  


What is class invariant in c++?

0 Answers  


C++ program output? Explain output of this program. #include <iostream> using std::cout; using std::cin; int main() {   cout<<cout<<' ';   cout<<cin;   return 0; } It prints some address in hexadecimal. what is it?

1 Answers  


Categories