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 a float in c++?

0 Answers  


Explain selection sorting. Also write an example.

0 Answers  


Differentiate between a copy constructor and an overloaded assignment operator.

0 Answers  


What is #include sstream?

0 Answers  


Describe the setting up of my member functions to avoid overriding by the derived class?

0 Answers  






Explain unexpected() function?

0 Answers  


What is low level language in simple words?

0 Answers  


What is a constant reference?

0 Answers  


Does c++ support exception handling?

0 Answers  


When a function is made inline. Write the situation where inline functions may not work.

2 Answers  


What it is and how it might be called (2 methods).

0 Answers  


What is a friend function in c++?

0 Answers  


Categories