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

What is function declaration in c++ with example?

0 Answers  


Explain virtual class and friend class.

0 Answers  


"How will you merge these two arrays? Write the program Array: A 1 18 22 43 Array: B 3 4 6 20 34 46 55 Output Array: C 1 3 4 6 18 20 22 34 43 46 55"

9 Answers   College School Exams Tests, HCL,


What is class definition in c++ ?

0 Answers  


What are different types of typecasting supported by C++

1 Answers   CA,






Describe the process of creation and destruction of a derived class object?

0 Answers  


Who created c++?

0 Answers  


How do you decide which integer type to use?

0 Answers  


What are the different types of comments allowed in c++?

0 Answers  


What will happen if a pointer is deleted twice?

0 Answers   Agilent, HAL,


Shall we use 'free' to free memory assigned by new, What are the further consequences??

5 Answers   Symphony,


What are c++ files?

0 Answers  


Categories