Stacks in C++

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2005
Posts: 8
Reputation: roscioeak@direc is an unknown quantity at this point 
Solved Threads: 0
roscioeak@direc roscioeak@direc is offline Offline
Newbie Poster

Stacks in C++

 
0
  #1
Feb 16th, 2005
Can anyone direct me where to go for doing stacks in C++. I have to make a program using stacks but can you initialize a stack with given values? If so can you give an example?
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 2
Reputation: littlewater is an unknown quantity at this point 
Solved Threads: 0
littlewater littlewater is offline Offline
Newbie Poster

Re: Stacks in C++

 
0
  #2
Feb 16th, 2005
en……maybe STL template lib may fulfill you need

but i always write a simple data-struct for the program...
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,141
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 948
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Stacks in C++

 
0
  #3
Feb 17th, 2005
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]
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 9256 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC