473,406 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

stack libraries

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
Jul 22 '05 #1
4 1353
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
Jul 22 '05 #2
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
Jul 22 '05 #3
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
Jul 22 '05 #4
On Sun, 6 Jun 2004 16:12:02 +0200 in comp.lang.c++, "Mario"
<mm********@hotmail.com> 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?

Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: NadaHombre | last post by:
Hello, If I want to make a class which is a stack of objects of some specific type (not just "Objects"), what is the best way to do it? I wonder if there is some generally accepted "best" way to...
11
by: Dan Elliott | last post by:
Hello all, I am writing a program which needs to run as quickly as possible, but holds a lot of data in memory (around 1GB for a usual run). Is this too much memory to even consider putting...
21
by: puzzlecracker | last post by:
Guys - Is it possible to find which way system stack grows? Perhaps, I am not precise enough: When a function is called, the return address of (callee) function is put on the stack. Thus, the...
18
by: Dev | last post by:
I'm working with some IBM sponsored C APIs to interface with a corporate legacy system, and it seems that I'm getting some stack corruption after any API call. I believe the APIs were designed...
4
by: Christian Christmann | last post by:
Hi, I'd like to store structs on an STL stack. Here is a piece of my code: #inclue <stack> ... struct storeInfo {
24
by: John | last post by:
I know this is a very fundamental question. I am still quite confused if the program call stack stack should always grows upwards from the bottom, or the opposite, or doesn't matter?? That means...
20
by: deepak | last post by:
Hi All, In C I heard the stack grows from top to bottom and heap from bottom to top. Is it compiler depend?
7
by: ifoundgoldbug | last post by:
Ok here is a short description of what i am doing. I need to program a dll for use by another program. the dll compiles fine but when i call it from another program i get a stack corruption of...
1
by: yaarnick | last post by:
Create a linked list data structure library to hold strings. Then library should support the following linked list operations. Create() – Creates the linked list Insert() – Insert a string into the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.