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

Write a recursive program to calculate factorial in c++.

0 Answers  


What is the use of static functions?

10 Answers   Symphony,


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

0 Answers  


What is dangling pointers?and what is memory leak?

5 Answers  


Why is c++ still popular?

0 Answers  






what are function pointers?

0 Answers  


The "virtual" specifier in a member function enables which one of the following? a) Monmorphism b) Late binding c) Metamorphism d) Solomorphism e) Inheritance

4 Answers   Quark,


How many types of comments are there in c++?

0 Answers  


What are c++ data types?

0 Answers  


What is difference between initialization and assignment?

12 Answers   HCL, HP, Infosys,


How do you clear a set in c++?

0 Answers  


what does the following statement mean? int (*a)[4]

0 Answers  


Categories