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

Explain about Garbage Collector?

651


How can you quickly find the number of elements stored in a dynamic array? Why is it difficult to store linked list in an array?

562


Explain the term memory alignment?

687


What is a container class? What are the types of container classes in c++?

680


Explain pass by value and pass by reference.

595






What is fflush c++?

580


What's the most powerful programming language?

598


What are guid?

691


What is #include math h in c++?

574


What relational operators if statements in c++?

646


What is & in c++ function?

597


Can I learn c++ in a week?

583


write a function signature with various number of parameters.

567


What are the sizes and ranges of the basic c++ data types?

589


find the two largest values among the 6 numbers using control structures : do-while,for,if else,nestedif- else ,while. one or two of them.

2001