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.
64
questions
44
votes
2
answers
40k
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,...
10
votes
2
answers
641
views
An attempt at a toy Vm
I usually use c++ so it may not be best practice for c.
This is a stack based toy vm and as a result it is very primitive, and it has no bitwise
instructions
64k might be a bit overkill for a toy vm.
...
6
votes
2
answers
2k
views
Stack implementation using vectors and templates with no overflow version 1.1
I have modified my code as per the suggestion given by some of the developers. Let me know if there are any further concerns or scope for improvements.
Original Version
...
5
votes
2
answers
225
views
Stack implementation using vectors with no overflow version 1.0
This is an implementation of a stack where I have used vectors. Can anyone please review it and let me know how I can improve this code and overall coding practice?
...
31
votes
7
answers
67k
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,...
10
votes
4
answers
2k
views
Array implementation of Java Stack
As an exercise, I wanted to make an array implementation of Stack, including most of the methods from the native Java Stack.
I'...
8
votes
2
answers
19k
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 ...
6
votes
3
answers
4k
views
Simple stack implementation using linked list
Please review my Stack using linked list:
...
5
votes
3
answers
383
views
Stack implementation using vectors and templates with no overflow version 1.2
Below is the code for stack along with one or two extra options. Kindly let me know if there are any concerns/critical issues. Below are the two link for previous versions.
Original
Version 1.1
<...
4
votes
3
answers
1k
views
Generic Stack Data Structure Using Linked Lists
I am a mathematician attempting to become proficient with C++. At the moment I am learning about data structures. I am now writing a stack data structure using linked list from scratch.
I have tested ...
4
votes
2
answers
2k
views
XML Writer in C++ - Updated
I recently posted about a basic XML writer in C++ and got a lot of great feedback. Well, I'm back with an updated version of the XML writer that is a bit less basic, but hope it's better than the ...
4
votes
3
answers
5k
views
Stack without use of STL - version 1.0
This is a basic implementation of a stack. Can anyone please review it and let me know how I can improve this code and overall coding practice?
...
3
votes
3
answers
1k
views
Improved stack implementation using a linked list
This is a followup to
Simple stack implementation using linked list
Since my original stack implementation has lots of bugs that I did not notice, I thought I would recreate and try to improve it. ...
3
votes
1
answer
148
views
Python3 Stack implementation with List built-in - Round Two
Previous code is available at Python3 Stack implementation with List built-in, this is a second-round review after I made alterations.
Once again, let's review my Stack implementation, with built-in ...
2
votes
2
answers
3k
views
My own Stack Implementation in Java
Please review my Stack implementation and let me know if you have any suggestions.
...
14
votes
3
answers
2k
views
Stack Implementation in C++ with Exceptions
Appreciate your thoughts and feedback...
Stack.h
...
11
votes
3
answers
15k
views
C++ Stack using template
I'm learning C++, so I wrote a stack with the help of templates. I'm wondering if there is anything I can improve or if I did something vastly wrong.
Stack.h
...
10
votes
6
answers
24k
views
Reversing a String using Stack
Is this code okay?
...
8
votes
5
answers
1k
views
Java Stack Implementation
I'm looking for a code review on my Stack Implementation in Java. Specifically I am looking for correctness, style, and efficiency. Thank you!
...
8
votes
2
answers
8k
views
Balance braces method
This is a continuation of this question, at least the first part of that question.
I want to check if everything in the new code is right or if there are other way to make it better.
Exercise
The <...
7
votes
1
answer
6k
views
Optimizing Efficiency in a Stack
I'm solving a problem on HackerRank where I'm required to implement a simple stack.
It's passing all the tests except for the last 4 where it fails due to surpassing the time constraint of 10s. ...
7
votes
3
answers
1k
views
C pointer based growable stack
This is my first attempt at writing a C program, it a generic stack that can grow accordingly. It appears to work correctly, however I am worried that is just a fluke and I could be doing something ...
7
votes
1
answer
2k
views
Calculator in C - Parsing arithmetic expression using the shunting-yard algorithm
This is a simple arithmetic calculator, which parses mathematical expressions specified in infix notation using the shunting-yard algorithm. This is one of my personal projects and I would love to ...
7
votes
2
answers
914
views
Concurrent stack in C
(See also the follow-up question.)
I was in the mood for pthread.h and decided to write a concurrent stack data structure. My requirements:
the stack has maximum ...
6
votes
2
answers
227
views
Is there a circular reference in a set of template substitutions?
I have a configuration engine that allows the user to specify a dictionary with text templates (read from a JSON file) where each placeholder like {x} can be ...
6
votes
3
answers
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
2
answers
449
views
Stack implementation in C++ using linked list
I am learning C++ and I made a simple stack class using a (reversed) linked-list to test my knowledge.
Are there any problems with the following code, or any suggestions to improve it?
I want to ...
6
votes
1
answer
2k
views
Lock-free bounded stack in C++11
Here is a classical attempt to implement a lock-free stack (based on this article). I rewrote it in C++11 and also tried to add memory orders which I would like to confirm to be correct.
...
6
votes
3
answers
512
views
Stack with getMin method
This should implement a stack that has a \$O(1)\$ getMin method. I used an auxiliary stack. Please provide comments on my solution.
...
6
votes
2
answers
1k
views
Three stacks in a single array
I have implemented three stacks in a single array in Java. Any advice on object oriented design, coding structure, logical part or any sort of advice would be appreciated.
...
6
votes
1
answer
122
views
Dynamically-sized stack - follow-up 2
Follow up of - Dynamically-sized stack - follow up
I've took the tips given to me, and what I did now is:
changing the function names to have a prefix
making the ...
6
votes
1
answer
30k
views
Reverse Polish Notation Calculator in Java
I created a highly effective Reverse Polish Notation calculator using Java 8, but am uncertain if there are any better ways to handle the problem. Feedback on any evident taboos and bugs is greatly ...
5
votes
3
answers
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 ...
5
votes
4
answers
3k
views
ADT stack with a dynamic array
I'm starting to learn about data structures and coding in C. The stack is the simplest of all data structures so I'm trying to implement an ADT stack with dynamically allocated array in C. This ...
5
votes
1
answer
170
views
Concurrent stack in C - follow-up
This is a follow-up question to Concurrent stack in C
The pop function not just removes the top element from the stack, but also returns it.
If a pthreads call ...
5
votes
4
answers
2k
views
Python Stack Implementation
This is my Stack implementation in Python.
...
5
votes
2
answers
342
views
Stack implemented using a single linked list
I am studying data structures and I have implemented a stack using a linked list.
stack.h
...
5
votes
4
answers
2k
views
Implementing two stacks using single array in java
Please review the code
...
4
votes
3
answers
602
views
Python3 Stack implementation with List built-in
So, inspired by this other code review, I wanted to see if I could implement a very basic stack without the linked-list approach taken by the OP in their implementation.
To that end, I came up with ...
4
votes
1
answer
2k
views
Stack - Implemented as Singly Linked List
Note: I do know that Python libraries provide a Linked List and Stack. This implementation has been done to practice ...
4
votes
2
answers
304
views
Dynamically-sized stack - follow up
Follow up of - Which is a better implementation of a stack data structure (based on an array)?
Please review my stack implementation from before. I've made it dynamically sized if needed and made a ...
4
votes
1
answer
71
views
C pointer based growable stack rev2
Following on from my previous question: C pointer based growable stack
I have made some improvements (hopefully!) based on the very helpful comments and suggestions.
I have checked that the stack can ...
4
votes
4
answers
2k
views
Class that implements a queue using two stacks
I am looking for a review of my code that implements a MyQueue class which implements a queue using two stacks.
...
4
votes
1
answer
414
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?
...
3
votes
4
answers
356
views
Passing Programs To A Stack Machine Implemented In C++
I'm learning C++ by implementing a previous project I did in Python. This is a simple stack machine which evaluates mathematical expressions, e.g. pow(9, 12). The code to run this on the stack ...
3
votes
1
answer
423
views
C++ Updated Stack Code
The original question can be seen here: Stack implementation in C++ using linked list
Changes (with the help of Martin):
Added copy constructor and assignment operator overload
Changed return type ...
3
votes
1
answer
203
views
Generic stack implementation
The provided code (a header-only library inspired by stb libraries] defines functions for creating a stack, pushing elements onto the stack, popping elements from the stack, peeking at the top element ...
3
votes
2
answers
295
views
Queue using Stack
I implemented this solution for the problem. Please provide feedback and review if this can be improved in any way.
...
3
votes
1
answer
334
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/...
2
votes
2
answers
91
views
Generic stack implementation (revision)
The below post is a follow-up of Generic stack implementation.
Below follows a header-only implementation of a generic stack (inspired by stb-libraries, following these guidelines: stb-howto.txt). ...