Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > stack libraries

Reply
Thread Tools

stack libraries

 
 
Mario
Guest
Posts: n/a
 
      06-06-2004
Hi
i´m searching for a good stack solution also, but is there no stack librarie
in the standart libraries like the string class?
and if there is a stack class how to use
thanks a lot
mario


 
Reply With Quote
 
 
 
 
Phlip
Guest
Posts: n/a
 
      06-06-2004
Mario wrote:

> i´m searching for a good stack solution also, but is there no stack

librarie
> in the standart libraries like the string class?
> and if there is a stack class how to use


#include <list>

class Stack {
public:
void push(int);
int pop();

private:
std::list<int> m_ints;
};

Notice your client code should not know there is a std::list<> in there.
Clients should only push and pop the stack. Implementation of push and pop
are up to you, but they will probably immediately delegate to std::list<>
methods.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces


 
Reply With Quote
 
 
 
 
Petec
Guest
Posts: n/a
 
      06-06-2004
Mario wrote:
> Hi
> i´m searching for a good stack solution also, but is there no stack
> librarie in the standart libraries like the string class?
> and if there is a stack class how to use
> thanks a lot
> mario


The standard library does have a stack:

#include <stack>
std::stack<int> stack;
stack.push(123);
int v = stack.top(); stack.pop();

Replace "int" with whatever type you want it to store.

- Pete


 
Reply With Quote
 
Petec
Guest
Posts: n/a
 
      06-06-2004
Phlip wrote:
> Mario wrote:
>
>> i´m searching for a good stack solution also, but is there no stack
>> librarie in the standart libraries like the string class?
>> and if there is a stack class how to use

>
> #include <list>
>
> class Stack {
> public:
> void push(int);
> int pop();
>
> private:
> std::list<int> m_ints;
> };
>
> Notice your client code should not know there is a std::list<> in
> there. Clients should only push and pop the stack. Implementation of
> push and pop are up to you, but they will probably immediately
> delegate to std::list<> methods.


Aside from the fact that the standard library already has a stack class,
wouldn't a std::deque<> be a better choice than std::list<> ? The standard
one defaults to the deque.

- Pete


 
Reply With Quote
 
David Harmon
Guest
Posts: n/a
 
      06-06-2004
On Sun, 6 Jun 2004 16:12:02 +0200 in comp.lang.c++, "Mario"
<> wrote,
>Hi
>i´m searching for a good stack solution also, but is there no stack librarie
>in the standart libraries like the string class?


What is wrong with std::stack for your purpose?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does std::stack::pop() not throw an exception if the stack is empty? Debajit Adhikary C++ 36 02-10-2011 08:54 PM
standard libraries don't behave like standard 'libraries' Sriram Srinivasan Python 13 11-12-2009 06:05 PM
C/C++ compilers have one stack for local variables and return addresses and then another stack for array allocations on the stack. Casey Hawthorne C Programming 3 11-01-2009 08:23 PM
stack frame size on linux/solaris of a running application stack Surinder Singh C Programming 1 12-20-2007 01:16 PM
Using mandatory libraries (custom class loading vs. expanding libraries) Karsten Wutzke Java 21 06-29-2007 09:25 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57