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
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,...
konijn's user avatar
  • 33.2k
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. ...
SomeDude's user avatar
  • 109
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 ...
Unbreakable's user avatar
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? ...
Unbreakable's user avatar
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,...
JavaDeveloper's user avatar
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'...
Stefan Rendevski's user avatar
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 ...
Scholar's user avatar
  • 83
6 votes
3 answers
4k views

Simple stack implementation using linked list

Please review my Stack using linked list: ...
lightning_missile's user avatar
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 <...
Unbreakable's user avatar
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 ...
Snorrlaxxx's user avatar
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 ...
CodeMonkey's user avatar
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? ...
Unbreakable's user avatar
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. ...
lightning_missile's user avatar
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 ...
Thomas Ward's user avatar
  • 2,518
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. ...
Sandeep Kumar's user avatar
14 votes
3 answers
2k views

Stack Implementation in C++ with Exceptions

Appreciate your thoughts and feedback... Stack.h ...
SRG's user avatar
  • 405
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 ...
Caresi's user avatar
  • 113
10 votes
6 answers
24k views

Reversing a String using Stack

Is this code okay? ...
Arun Prakash's user avatar
  • 1,483
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! ...
Gauri Ramesh's user avatar
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 <...
Emilio Gort's user avatar
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. ...
Jonathan Spiller's user avatar
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 ...
NoOdle's user avatar
  • 133
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 ...
Andy Sukowski-Bang's user avatar
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 ...
coderodde's user avatar
  • 27.8k
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 ...
t3chb0t's user avatar
  • 44.2k
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 ...
2013Asker's user avatar
  • 1,979
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 ...
Samueljh1's user avatar
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. ...
inspirit's user avatar
  • 203
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. ...
giulio's user avatar
  • 743
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. ...
Muztaba Hasanat's user avatar
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 ...
gues532's user avatar
  • 339
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 ...
T145's user avatar
  • 3,089
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 ...
Moeb's user avatar
  • 259
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 ...
diwakar_wagle's user avatar
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 ...
coderodde's user avatar
  • 27.8k
5 votes
4 answers
2k views

Python Stack Implementation

This is my Stack implementation in Python. ...
Melissa Stewart's user avatar
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 ...
In78's user avatar
  • 643
5 votes
4 answers
2k views

Implementing two stacks using single array in java

Please review the code ...
wandermonk's user avatar
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 ...
Thomas Ward's user avatar
  • 2,518
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 ...
BlooB's user avatar
  • 293
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 ...
gues532's user avatar
  • 339
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 ...
NoOdle's user avatar
  • 133
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. ...
user avatar
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? ...
Emanuele's user avatar
  • 240
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 ...
redexe's user avatar
  • 31
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 ...
Samueljh1's user avatar
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 ...
Harith's user avatar
  • 4,880
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. ...
Neelesh Salian's user avatar
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/...
Alex D's user avatar
  • 297
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). ...
Harith's user avatar
  • 4,880