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
8
votes
2answers
18k views

STL Stack Implementation

I implemented std::stack from the STL for deeper understanding of the language and memory since I still am only a beginner. I implemented the stack using a singly ...
5
votes
3answers
2k views

How Does This Naive Stack Implementation Look?

Consider this naive stack implementation in Elixir: ...
5
votes
1answer
260 views

Managing People in a SimCity Clone

So I am working through a few different game ideas as I learn programming, and I could definitely use some feedback on my latest project. This is a simple SimCity clone. So far I have created a City ...
7
votes
3answers
32k views

Stack implementation using an array

I am trying a stack implementation using an array. I want to know if this approach is OK or if there is a logical problem. This program is working fine. ...
3
votes
1answer
334 views

Infix to postix conversion

I'm looking for code review, optimizations and best practices. Also verifying complexity to be O(n), where n is the string length. ...
15
votes
4answers
22k views

Implementation of stack using pointers

Please review my code and let me know how I can possibly improve it. ...
25
votes
1answer
2k views

Stack implemented using linked list in x86_64 assembly

I wrote a stack implementation using a singly linked list in x86_64 assembly. This stack supports the usual push/pop operations ...
39
votes
2answers
35k views

Balanced parentheses

Given an expression string exp, write a program to examine whether the pairs and the orders of "{","}","(",")","[","]" are correct in exp. For example,...
29
votes
7answers
64k views

Check for balanced parentheses

Given an expression string exp, write a program to examine whether the pairs and the orders of "{","}","(",")","[","]" are correct in exp. For example,...
6
votes
1answer
937 views

Functional, but not recursive, tree traversal

To learn tree traversal i implemented os.walk, tail-recursive and stack-based. Unfortunately Python doesn't support tail call optimization. How do i rewrite my ...
4
votes
3answers
5k views

Retrieve min from stack in O(1)

I wrote some Python code to solve the following problem. I'm curious to see if someone else can find a better solution, or critique my solution. How would you design a stack which, in addition to ...
10
votes
3answers
2k views

Making an atomic transaction out of several operations

I'm looking for a design pattern or suggestions that can help refactor my code into something a bit less repetitive. I have a method that has several sequential steps (10-15) that if any of them fail ...
7
votes
2answers
6k views

Int stack implementation

...
11
votes
1answer
2k views

Undo and redo functionality for a GTK+ program

I'm working on a small GTK+ program and I'm now implementing undo and redo capabilities. This is the code that I'm using to handle the different states. It's just a linked list storing the allocated <...
3
votes
2answers
209 views

Dynamic stack in C - new version

Not long ago, I posted this dynamic stack for review. Now I wrote a new version, which is hopefully a better one. Please take a look and let me know how I could improve performance and increase code ...
6
votes
3answers
3k views

Dynamic stack implementation

I wrote this code for a dynamic stack and would like to know what would be better if done differently. It can increase memory by a percentage and/or fixed value when needed. It can also be set to not ...
-6
votes
2answers
4k views

Code review: infix to postfix converter [closed]

...
2
votes
2answers
45k views

Postfix evaluation using a stack

I just wrote the code to evaluate a postfix expression and would like it if someone reviews it for me, it works perfectly fine but I'm having trouble adding the character "=" at the end. ...
4
votes
1answer
390 views

Multi producer/consumers lockfree stack

Can you please take a look at the following x86-64 C++ code which should implement a multi consumer/produce lockfree stack? Do you think I have missed anything? ...
6
votes
4answers
6k views

Reviewing my implementation of a stack using linked list

I have been studying data structures, and I'm new to this. Here is my code for the push and pop operations. I considered using a node=top, so that I can avoid O(n) operations for the push (i.e. ...
3
votes
2answers
176 views

Is it needed to “beautify” this Stack implementation?

I'm just learning OOP, and I have an assignment to create a Stack. I came up with the following. Is it "beauty" enough, or to "schooly". Where can I evolve? This is the class: ...
14
votes
2answers
114k views

Stack implementation using linked list

This is a working stack implementation using a linked list. I'm just curious to know if this is a good way of doing it. Any suggestions are welcome. Can we keep track of the number of elements in ...
6
votes
1answer
2k views

How is my implementation of an immutable stack?

Below is my implementation of an immutable stack class. The reverse function is trying to return a stack with all elements reversed. Is my implementation good? Maybe the reverse function can be ...
6
votes
3answers
9k views

Linked stack implementation in C++

Please feel free to be as harsh as possible. Implementation file: ...
8
votes
1answer
8k 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
329 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
776 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
262 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: <...
2
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
901 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
1k views

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

There at least 2 patterns of using Stack.Pop ...
2
votes
2answers
930 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. ...
6
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
420 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 ...
25
votes
1answer
992 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
312 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: ...