Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

21
votes
3answers
4k views

Leetcode: Valid parentheses

https://leetcode.com/problems/valid-parentheses/ Given a string containing just the characters (, ), ...
1
vote
1answer
229 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 ...
5
votes
2answers
121 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 ...
2
votes
2answers
86 views

Using the stack algorithm for parenthesis matching

I have used Stacks to check for brackets mismatch. (Parentheses matching problem using Stack algorithm) Any suggestions on how to improve the code? I have tried various examples and it works ...
3
votes
2answers
145 views

Stack implementation in C++ including min(), max() functions in O(1)

This implementation seems to work. I would love to get any suggestions / comments on how this code could be improved. Are there any potential memory management issues? Any additional methods that ...
1
vote
2answers
37 views

Stack Array implementation of Java

This is my array implementation on stack in Java. It involves push, pop, get and growth when limit of array size is reached. I am a self-taught programmer starting to learn data structures and ...
1
vote
1answer
129 views

Stack using Linked List in Swift

I made this implementation of a stack in Swift that stores its elements as a linked list. It seems to work perfectly well, but I’m wondering how I can improve it to follow the best practices of the ...
2
votes
3answers
122 views

Implementing a stack using a linked-list

In my intro CS class we're reviewing data structures. I'm currently working on implementing a stack using a linked list (LIFO) in C. I'd appreciate a review of the implementation as well as of my ...
2
votes
2answers
93 views

LinkedList Stack Implementation

I'm new to the programming and I want to ask a question about my linkedlist stack implementation if it's correct and if it meets the requirements of the linkedlist stack implementation. If there is ...
3
votes
0answers
84 views

Generic stack data structure using linked list and smart pointers

I have decided to rewrite what I did here, following the suggestions to use smart pointers. I will rewrite the other data structures as well using smart pointers where appropriate. I just want to see ...
3
votes
0answers
89 views

All the paths from the root to the leaves

Given a binary tree, return all root-to-leaf paths. Example: -- 1 / \ 2 3 \ 5 Output should be: ["1->2->5", "1->3"] My approach: I walk the branches ...
0
votes
1answer
138 views

Iteratively determine the diameter of a binary tree

Can the performance of the iterative approach be improved? I find that this approach lags behind many recursive options. no recursive answers, please. Baseline recursive approach: takes 52 steps ...
3
votes
2answers
67 views

A Stack Implementation In C

I've written a very simple linked list based stack implementation and was wondering if this is the standard way to do it in C. ...
1
vote
3answers
81 views

Stack implemented with linked list

I have looked at some previous posts and changed my code accordingly. Do you have some suggestions about my current code? Here are my specific questions: What should ...
3
votes
2answers
149 views

Implementing a stack with Java

I am trying to implement a stack with Java: ...
3
votes
3answers
300 views

Threadsafe Stack

Here is a class which I have written to create a simple Stack data structure which can be shared across multiple threads. It's a simple LIFO which has 2 operations: one to push onto the top of the ...
5
votes
3answers
195 views

Abstract Data Type: Stack implementation in C++

While trying to get better at C++ I tried my hand at making a stack implementation. This is the result: ...
4
votes
3answers
643 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 ...
2
votes
1answer
67 views

Unit Testing- simple stack class

This is my first real attempt at unit testing. This is an area I'm currently focused on improving. I say this because I would greatly appreciate any and every improvement! Stack code: ...
3
votes
0answers
287 views

Find redundant braces in an input string

I am solving interview questions from here. Problem : Write a program to validate if the input string has redundant braces Return 0/1 : ...
3
votes
3answers
1k views

Array-based stack

Description: An array-based Stack class. Since this class is designed using an array the size of the Stack is limited to ...
3
votes
2answers
75 views

Python 2 Stack and LinkedList implementation

I'm currently implementing data structures and algorithms I studed in my college course. This is my implementation of a singly linked list and a stack. I would appreciate some feedback in terms of the ...
0
votes
0answers
115 views

Linked list stack with O(1) push, pop and max operations

I chose to implement the max stack with a linked list due to the guarenteed O(1) push and pop. Added the max. Just looking to see if this can be done any better or if there are any other improvements....
4
votes
2answers
1k views

Check if brackets are balanced

...
6
votes
1answer
117 views

Multiple stacks implemented via a linked lists on top of single fixed-size array

Problem Statement Originally, the problem is defined in the book as following: Describe how you could use a single array to implement three stacks. — Cracking the Coding Interview (6th edition) ...
-1
votes
2answers
96 views

List operation while implementing stack

This is a very basic problem of implementing a queue operation using two stacks. Until now there are no issues with the logic but the testing tool report it takes more time than usual. Test case ...
10
votes
4answers
491 views

Validator for mathematical expression in infix form

This program will validate whether a mathematical expression entered by the user is a valid expression based off whether the expression itself has been entered with the correct scope openers and scope ...
8
votes
1answer
153 views

Compute the height of a tower made of buckets

I need to speed up my algorithm. It is about finding the height of a tower. The tower is built from buckets. Each bucket has height and radius (1 <= height,radius <= 1000). Variable ...
4
votes
1answer
157 views

Stack implementation with singly linked list

The following is my implementation of a stack using a linked list. ...
4
votes
1answer
597 views

Stack implementation using a singly linked list

I've implemented a stack using a singly linked list and would like to know if there are any things I could improve on. StackList.h: ...
2
votes
3answers
300 views

A Stack Template

Why you're here: Today I bring you a simple Stack Machine and a Lot of questions. I am trying to gain a little bit more understanding of pointers, memory management and templates and thought a Stack ...
-1
votes
0answers
91 views

C program to convert prefix expression to postfix

Here is my code that takes in prefix expression and converts it into postfix. it makes use of stacks. whenever alphabet comes, it is pushed, when a +-/* comes, two strings are popped, they are ...
1
vote
2answers
205 views

Converting prefix expressions to infix

Here is my new working code. Man, working with strings in C is tedious and annoying. I had built the algorithm in short time, took hours figuring how to implement it properly in C. Tell me if there ...
1
vote
2answers
414 views

Eight Queens Recursive

I am working on a Java textbook chapter on recursion, and I am to implement an Eight Queens solution using recursion. Though I know that I am to post working code in Code Review, I do believe this ...
14
votes
3answers
1k views

Stack Implementation in C++ with Exceptions

Appreciate your thoughts and feedback... Stack.h ...
0
votes
2answers
102 views

C++ Stack implementation with linked-list

It's proving difficult to find implementations of a Stack with linked list and Im trying to figure out if my implementation is correct/not missing anything obvious. ...
4
votes
3answers
428 views

Stack data structure implementation in Java

I recently made a data structure, stack implementation in Java and I would like feedback on my code to improve it (other than commenting/documenting my code). ...
1
vote
1answer
117 views

Stack calculator in Racket

I have implemented a stack calculator based on this programming task. I wondered if a more experienced racketeer could give me feedback and tell me if I am missing anything in Racket that would enable ...
3
votes
2answers
562 views

Python stack and queue classes, implemented using lists

I have made a stack and queue implementation with OOP in Python (sorry for variable names) . It is made from scratch. I just watched a video how these two things work. I am still trying to improve in ...
1
vote
2answers
407 views

Remove all adjacent duplicates in a string using a Stack

Input: careermonk Output: camonk Input: mississippi Output: m I want to improve this code. ...
2
votes
3answers
355 views

Implement a stack class in Python

Problem : Implement a stack class in Python. It should support 3 APIs: stack.top(): prints element at top of stack stack.pop(): takes out an element from top of stack, stack.push(): ...
4
votes
1answer
130 views

Generic fixed-size Stack implementation in C

Coming mostly from C#/Java background, I'm trying to implement a simple fixed-size stack data structure in C. The main concern about the "fixed-size" part is that pushing new elements to a full stack ...
0
votes
2answers
63 views

Another Stack implementation in Java

I'm trying to write my own stack implementation using LinkedList. It looks like it is doing what it should doing. But how does it look from a design perspective? ...
2
votes
1answer
56 views

Stack implementation in python using jupyter

This is my first program in Python: a stack implementation. ...
0
votes
1answer
337 views

Codility voracious fish are moving along a river [closed]

I am trying to solve the codility problem: N voracious fish are moving along a river. Calculate how many fish are alive. Codility Problem My code get only 50 percent of 100. Could you tell me ...
6
votes
1answer
95 views

Move-aware noexcept stack in C++

I'm learning C++, and move semantics and exception safety seem to be a top priority when using the language. I implemented the simplest data structure I could think of. ...
4
votes
2answers
809 views

Fixed size rolling Stack

This is a stack implementation that only retains the last x elements that are added. I have also added an IStack interface to allow alternate stack implementations in the future. The main use case i ...
2
votes
1answer
126 views

Stack for asynchronous processing

The following TaskStack processes input elements asynchronously based on a function that it receives at construction: ...
3
votes
1answer
305 views

Mirror a stack of Integers

Write a method mirror that accepts a stack of integers as a parameter and replaces the stack contents with itself plus a mirrored version of itself (the same ...
0
votes
1answer
925 views

Check if a stack of Integers contains a sequence of consecutive values

Write a method isConsecutive that takes a stack of integers as a parameter and that returns whether or not the stack contains a sequence of consecutive integers ...