The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
1
vote
2answers
798 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
116 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
448 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
236 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
753 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
686 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
673 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
200 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
58 views

Stack implementation in python using jupyter

This is my first program in Python: a stack implementation. ...
0
votes
1answer
601 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
139 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
1k 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
155 views

Stack for asynchronous processing

The following TaskStack processes input elements asynchronously based on a function that it receives at construction: ...
3
votes
1answer
497 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
1k 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 ...
3
votes
1answer
129 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 ...
4
votes
3answers
558 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 ...
5
votes
4answers
1k views

Python Stack Implementation

This is my Stack implementation in Python. ...
3
votes
3answers
1k views

HackerRank (Stacks) - Maximum element solution gets a timeout

Apparently my solution is really slow. Can someone help me with why my solution passes a little over half the test cases for this question? Here is my solution: ...
4
votes
4answers
1k views

Checking if a Stack is sorted in ascending order

Write a method isSorted that accepts a stack of integers as a parameter and returns true if the elements in the stack occur in ascending (non-decreasing) order ...
6
votes
2answers
2k views

Stack using a Linked List

I thought implementing a stack using a linked list was a good option since an array implementation involves reallocation of array size and so on. I have implemented basic ...
2
votes
1answer
3k views

Check two stacks for equality

Write a method equals that takes as parameters two stacks of integers and returns true if the two stacks are equal and that returns false otherwise. To be ...
6
votes
1answer
293 views

Leetcode number of atoms solution using stack

LeetCode 726. Number of Atoms Given a chemical formula (given as a string), return the count of each atom. An atomic element always starts with an uppercase character, then zero or more ...
2
votes
1answer
552 views

Stack-based state machine

Is everything alright with this code? What can I add to it? state.h: ...
2
votes
1answer
635 views

Stack using linked List

I have this problem with my interview. I was asked to implement a stack using a linked list. Gist ...
5
votes
5answers
1k views

LeetCode parentheses matching

I came across this question from LeetCode OJ where I am given a string containing parentheses and I need to find out if the string contains valid matching parentheses or not. Given a string ...
9
votes
4answers
4k views

Checking for parentheses balance in C

A recent assignment asks me to create a program that checks for parentheses balance in a given string. As I can't find any duplicate questions that have code written in C, I decided to post another ...
2
votes
1answer
51 views

JavaScript Queue Attempt #2

This is a follow-up review to JavaScript queue implementation using linked list I've run the code through a linter, fixed every style error, added const where it ...
9
votes
2answers
2k views

A counterexample in balanced parentheses

In this program I had to analyse if the parenthesis given are well balanced. For instance, input (()) is correct and input ())(()...
1
vote
1answer
394 views

Analyzing an arithmetic expression using stacks

I'm looking for some constructive (harsh) criticism of a homework I've done (the code works fine). Also Is there a better/another way to solve the exercise? Exercise: Read an arithmetic expression ...
2
votes
1answer
54 views

A C stack with minimum and maximum values

I have this C stack implementation that knows its minimum and maximum values: minmax_stack.h ...
4
votes
3answers
137 views

Implementation of a simple stack with min method

The problem statement: Implement a stack which has push and pop method and also min method whereas min method has \$O(1)\$ complexity. From an interview standpoint, what mistakes would you point ...
4
votes
2answers
524 views

JavaScript animation effect stack

I am building a library that uses animations in a canvas. I need to apply effects to some objects in the canvas and I came up with an effect stack that contains each effect to be executed on a ...
6
votes
3answers
87 views

Minimal stack from unsigned int to track boolean values wtih bits

This grew out of a need to track sequential ctrl+shift+Left/Right-arrow keypress events on a gtk editor. It is a small stack implementation for boolean values (for <...
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 ...
10
votes
1answer
1k views

Dynamic stack C implementation

I'm a C beginner. I'm studying and implementing some data structures. I'd like to get feedback. This is a stack implemented with an dynamic array. In main there ...
7
votes
5answers
801 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! ...
4
votes
3answers
2k views

Implementation of Stack using Linked List

Please review my code and help me to improve it. I have written this code using template. Can I use more C++11? Is using top in this code is necessary? ...
1
vote
1answer
3k views

Stack implementation using nodes

Purpose Implement a Stack with push, pop, and peek ...
7
votes
3answers
1k views

Python implementation of stack to return minimum in O(1) time

I have written a stack in Python that is required to push, pop and return the minimum of the stack in \$O(1)\$ time. ...
1
vote
1answer
851 views

Iterative quicksort in Java

I have this quicksort implementation that relies on heap memory instead of actual stack. It uses two integer stacks for keeping track what subranges are yet to be sorted. When a partition routine is ...
0
votes
1answer
2k views

Queue/stack/node class Implementation

Below there are 3 short header files for queue, stack, and node implementation. I do ...
3
votes
2answers
2k views

Hackerrank CTCI “Stacks: Balanced Brackets” Javascript Solution

Here is the original problem, and below is my solution. I wonder what can be improved? Or is there a fundamentally better algorithm out there? Thank you! My intuition is telling me that it can be more ...
5
votes
2answers
504 views

Concurrency-safe stack implementation in Go

As Go doesn't come with a lot of collection structures, I've implemented stacks myself, building off some sample code I found floating around. I've then tried to extend it further by: Making a "...
0
votes
2answers
134 views

Linked List Stack

I have no trouble with my code on working part but I still have some worries if there is something missing so I want a review for my code. Also, I wonder if the exceptions are true type for these ...
4
votes
2answers
8k views

FIFO, FILO, LIFO and LILO integer stacks in C

One of my current side projects includes a stack-based interpreter written in C for a programming language I'm designing, SSBL. Since the entire language is stack-based, I needed a way to create and ...
10
votes
3answers
2k views

Implementing a Stack with Templates and Smart pointers

I'm trying to understand the concepts of smart pointers and templates. To get a better understanding of these, I tried to implement these two concepts on Stack. I ...
6
votes
2answers
8k views

Iterating an array of nodes, each of which can have children

I've written some C# (7) code to iterate through a Node[], listing all of its nodes in order (i.e. child elements are listed immediately after the parent). Each <...