Questions tagged [stack]

A stack is a last in, first out (LIFO) abstract data type and data structure. Perhaps the most common use of stacks is to store subroutine arguments and return addresses.

Filter by
Sorted by
Tagged with
7
votes
3answers
9k views

Linked stack implementation in C++

Please feel free to be as harsh as possible. Implementation file: ...
10
votes
1answer
9k views

A working stack allocator

Here's an absolutely essential piece of C++ lore, a stack allocator, that will allow you to, say, allocate strings and vectors on the stack. There are 2 stack allocators I know of, here and here. The ...
11
votes
2answers
3k views

How can this simple coroutine implementation be improved?

This is a quick and dirty implementation of coroutines that implements yield by saving and restoring the stack to and from the heap. Here's an earlier version, which does the most naive possible thing,...
1
vote
3answers
5k views

Review implementation of stack by using pointers in C

After I had my code for stack implementation by array reviewed I wrote stack implementation by using pointers. Here's my code. Any suggestions for improvement are welcome. I'll be adding updated ...
0
votes
2answers
2k views

Review implementation of stack by using array in C [closed]

This question has become long after many updates. Click here to go down. I have implemented stack using arrays in C. Please give me suggestions on how to improve it. The purpose of writing it is ...
7
votes
3answers
333 views

Mimicking the basic interface of std::stack

I am trying to mimic std::stack in my implementation (just the basic interface - no iterators / allocators). Since I was having trouble handling all the memory ...
2
votes
2answers
1k views

Using pointers for string manipulation

I'm taking a sentence and determining whether or not it is a palindrome. I'm doing this while learning about stacks. Is there a way I can use pointers instead of ...
5
votes
1answer
807 views

Immutable C++ stack - thoughts and performance

What are your thoughts on the fallowing immutable stack implementation? It is implemented having as a basis a C# immutable stack (where garbage collector assistance does not impose using a reference ...
4
votes
2answers
267 views

Another stack implementation (in C)

I just started learning C and the online book contained the exercise 'implement a stack'. So I did, but thought I'd put it here, because I still don't feel comfortable with pointers. So here it is: <...
3
votes
3answers
4k views

Calculating postfix notation using two forms of input

My postfix program essentially allows the user two input options to calculate a postfix equation: Confirmations after each input (after an input, the user is ask for another number, operator, or ...
6
votes
2answers
2k views

Valid Parentheses

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the correct order, "()" and "()[]{}" are all ...
5
votes
4answers
940 views

Simple static integer stack

This question is about improving my C++ coding skills. I was asked to implement a simple static integer stack in C++ as an assignment. I've come up with the following code: ...
2
votes
1answer
4k views

Objective-C Stack implementation

I just started coding in Objective-C and would like to know if my simple implementation of a Stack is acceptable & what ways would you improve the Stack code, or the Main code? i'm curious of ...
8
votes
2answers
2k views

Which is the most correct pattern for using Stack.Pop?

There at least 2 patterns of using Stack.Pop ...
2
votes
2answers
947 views

RPN Evaluator that writes the results to a text file

For homework, I had to write an RPN Evaluator and write the results to a text file. I've done all that, but it feels weird, like the writing to my results text file. It also doesn't feel efficient. ...
8
votes
3answers
9k views

Simple array-based Stack class in Java

I have created a simple array-based Stack class with some methods like the actual Stack in Java. I am testing this for mistakes, but since I am learning Java, my tests may not be as comprehensive as ...
6
votes
3answers
424 views

implementation of a stack in C

Below is my implementation of a stack in C. Is it correct? And/or is there anything that I should fix to make it better in any way? stack.h ...
4
votes
3answers
3k views

Stack implementation using arrays

Please comment on the same. How can it be improved? Specific improvements I am looking for: Memory leaks C++ style Making code run faster RAII ...
6
votes
2answers
2k views

Java and stacks: correct implementation?

I created this very simple stack concept's implementation. Could you tell me if it is correct and clean? Do you see any bad coding habits? ...
4
votes
4answers
18k views

Linked list stack implementation

I have used the following code for a stack implementation. The top keeps track of the topmost node of the stack. Now since top ...
5
votes
1answer
6k views

Tree-traversal without recursion

I wrote the following code for printing all the paths to the leaf nodes in a tree (NOT a binary tree ) without using recursion. I have used a stack and performed dfs on the tree. Whenever I reach a ...
5
votes
3answers
4k views

Simple stack implementation

I am not experienced in C++, and wrote this code for implementing a stack data structure using a linked list. Can you please point out any flaws, errors, stupid mistakes, general improvements etc ...
26
votes
1answer
1k views

How can I make my stack monad faster?

I made a stack monad that lets one manipulate and control values on a stack. I want to know if it's correct (it seems correct), how to make it faster, and how I could detect stack overflows without ...
3
votes
1answer
314 views

Concurrent stack implementations in Ruby (relative performance of mutexes/CAS?)

This code is very simple, but it is intended as an experiment in the relative performance of mutexes/CAS on different platforms. The latest version can always be found at: https://github.com/...
7
votes
1answer
371 views

Song repetition manager with Stack

The exercise was to take a file such as this: ...
1
vote
3answers
14k views

Stack class in C++

Please review this: ...

1
4 5 6 7
8