| | |
Stacks in C++
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
This would be an example of a stack of integers using a list ...
[php]
// example of a stack (Last In First Out = LIFO) using a list
// compares to a stack of dinner plates
// Dev-C++
#include <iostream>
#include <list>
using namespace std;
int main()
{
list<int> iL;
int k;
// load the stack with numbers 0 to 9, last number entered would be on top
for(k = 0; k < 10; k++)
iL.push_front(k);
// now unload the stack and display
cout << "Unloading the stack in order:\n";
for(k = 0; k < 10; k++)
{
// read the top element of the list
cout << iL.front() << endl;
// now pop it (removes top element)
iL.pop_front();
}
cin.get(); // wait
return 0;
}
[/php]
[php]
// example of a stack (Last In First Out = LIFO) using a list
// compares to a stack of dinner plates
// Dev-C++
#include <iostream>
#include <list>
using namespace std;
int main()
{
list<int> iL;
int k;
// load the stack with numbers 0 to 9, last number entered would be on top
for(k = 0; k < 10; k++)
iL.push_front(k);
// now unload the stack and display
cout << "Unloading the stack in order:\n";
for(k = 0; k < 10; k++)
{
// read the top element of the list
cout << iL.front() << endl;
// now pop it (removes top element)
iL.pop_front();
}
cin.get(); // wait
return 0;
}
[/php]
May 'the Google' be with you!
![]() |
Similar Threads
- spotlight doesn't search hypercard stacks (OS X)
- Implementation of Stacks and Queues (C)
- evaluation of stacks (C)
Other Threads in the C++ Forum
- Previous Thread: Classes Problem
- Next Thread: help with errors
Views: 9256 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets







