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
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,...
6
votes
2answers
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
2answers
185 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? ...
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,...
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 ...
2
votes
2answers
1k views

My own Stack Implementation in Java

Please review my Stack implementation and let me know if you have any suggestions. ...
10
votes
4answers
1k 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'...
3
votes
3answers
3k 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? ...
6
votes
3answers
4k views

Simple stack implementation using linked list

Please review my Stack using linked list: ...
5
votes
3answers
355 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
2answers
1k 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
3answers
664 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 ...
3
votes
3answers
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
1answer
128 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 ...
11
votes
3answers
11k 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 ...
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 ...
5
votes
1answer
18k 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
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 ...
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 ...
14
votes
3answers
1k views

Stack Implementation in C++ with Exceptions

Appreciate your thoughts and feedback... Stack.h ...
10
votes
6answers
23k views

Reversing a String using Stack

Is this code okay? ...
8
votes
2answers
6k 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 <...
6
votes
1answer
1k 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
3answers
430 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
2answers
184 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 ...
5
votes
2answers
132 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 ...
5
votes
4answers
2k 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 ...
4
votes
4answers
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
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? ...
3
votes
2answers
244 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
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
2answers
424 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 ...
7
votes
5answers
789 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! ...
6
votes
2answers
843 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
1answer
105 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
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 ...
5
votes
4answers
1k views

Implementing two stacks using single array in java

Please review the code ...
5
votes
2answers
315 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
1answer
113 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
4answers
1k views

Python Stack Implementation

This is my Stack implementation in Python. ...
4
votes
3answers
550 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
2answers
247 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 ...
3
votes
1answer
1k 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 ...
2
votes
3answers
143 views

Stack implementation using vectors and templates with no overflow version 1.3

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 links for previous versions. Version 1.0 Version 1.1 ...
2
votes
4answers
3k views

Palindromes with stacks

I'm creating a simple function to verify whether or not a string is a palindrome, and must use stacks in solving it. ...
2
votes
1answer
623 views

Which is a better implementation of a stack data structure (based on an array)?

This is a version I made: ...
1
vote
1answer
427 views

Concurrent blocking stack

I just want to train before interview. I googled concurrency interview questions and one of the question was write concurrent ready stack. ...
1
vote
0answers
71 views

Mergesorting a stack in Java - a new algorithm

(See the previous iteration.) Now I have implemented a stack merge sort that does not have to reverse every substack after sorting it, and it allocates the two auxiliary stacks only once prior to the ...
1
vote
1answer
295 views

Stack without use of STL - Version 1.1

I had already posted this question at here and have tried to incorporate some of the suggestions given. Kindly let me know if there are still some concerns/suggestions/improvements in the code ...
1
vote
1answer
135 views

Mergesorting a stack in Java

(See the next iteration.) I have this small program for sorting a stack using mergesort. Basically, the aim was to use as little aid from JDK library as possible. See what I have: StackMergesort....