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.

learn more… | top users | synonyms

4
votes
2answers
615 views

Simple FIFO and LIFO ferry simulator

I am trying to make a ferry simulator with one ferry that works like a stack and another like a queue. I have a working class for stacks and queues with pop/push; I am trying to figure out how to ...
-1
votes
2answers
89 views

Stack using two queues

I have implemented the Stack using two Queues q1 and q2 respectively as shown below in the code. I would like to get you reviews on whether it's an efficient way of implementing it or now. For Pop ...
3
votes
2answers
480 views

Implementing two stacks using single array in java

Please review the code ...
5
votes
1answer
44 views

ADT stack with a dynamic array (revision 1)

Here's the second draft of my ADT stack code which I posted here before after carrying out most of the improvements suggested there. I decided to expose a function called ...
4
votes
1answer
41 views

Stack implementation using arrays in Java

Could someone please review my code and let me know if there is any scope for optimization for better performance. ...
5
votes
4answers
116 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
2answers
89 views

Java Max-Stack implementation to return maximum value in the stack

I have written the below program to write a Java stack implementation. I have added a method which returns the maximum value in the stack, e.g, a pop. The implementation for this is based on the Max ...
8
votes
3answers
373 views

Simple implementation of a generic stack

I'm fairly new to C++ programming. To help I've been writing my own data structures for practice. I'd liked this to be judged as if it was written by a professional, and receive honest feedback. I ...
3
votes
1answer
49 views

Stack implemented with a linked list

I have made a basic stack class utilizing a linked list for data storage and \$O(1)\$ push and pop and just want some basic feedback on the class to see if there is anything basic I missed. It seems ...
5
votes
1answer
107 views

Palindrome using stack

I recently started learning Java, algorithms, and data structures. I am trying to check if a string is palindrome. I would like a review to see where and how I could improve. ...
5
votes
3answers
328 views

Stack Implementation in C++

This is my first template implementation. I'm trying to learn C++ and Algorithms. Any constructive criticism on code quality, readability is welcome. Everyone has their own style, but there are ...
7
votes
1answer
112 views

Stack using an array

I designed a simple drop-out stack a while back. Basically, I just want to get a few opinions on whether or not this is a good implementation and whether I am understanding the concept of a drop-out ...
6
votes
3answers
688 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 ...
5
votes
4answers
509 views

A data structure with push(int x), pop(), min() and max() in O(1)

I have written this Java code for a data structure which includes 3 stacks to supports four operations in \$O(1)\$: push(int x), ...
4
votes
3answers
37 views

Balanced expression checker

This program detects whether an expression is balanced or not. I would like to know how I can make this more efficient. ...
-3
votes
1answer
94 views

Implemented Stack using array

I'm going to job interviews soon. How I can improve my coding style and write better code? ...
3
votes
1answer
87 views

Priority stack in Java

I have this (simple) data structure that maintains multiple LIFO stacks. Each such stack is assigned a priority. The less is the value of a priority key, the higher the priority. Pushing operation ...
10
votes
1answer
351 views

Stack implementation using Swift

I would like to request some code review and feedback on a stack implementation using Swift. Disclaimer: I might have not used protocols, optional unwrapping and error and ...
5
votes
1answer
87 views

Stack implementation using linked list in C++

I'd like some feedback for the code I wrote. I haven't programmed in C++ for two years. ...
2
votes
3answers
55 views

ADT Stack with a doubly circular linked list

I have managed to implement an ADTStack with a circular doubly linked list. I would like to know whether there are things I could have done better or, I should ...
6
votes
2answers
227 views

Stack implementation with a linked list

Could anyone provide any constructive criticism? I'm trying to get a jump on data structures before classes start. One thing is that I should add a copy constructor and assignment operator. Changes ...
4
votes
2answers
48 views

ADT Stack with LinkedList

I am currently preparing for my exam and I am trying to implement some abstract data types with linked lists as preparation for the exam. I found an older exam from my prof. and he wants us to ...
8
votes
3answers
269 views

Generic stack in C

I tried to implement a generic stack in C using void pointers and tried to keep it as simple as possible by delegating all responsibility to the caller of the ...
6
votes
1answer
142 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. ...
4
votes
1answer
86 views

Lock-free bounded stack atomics

I was thinking about using very basic bounded (preallocated) stack to keep track of my threads IDs in correct LIFO order. I was wondering if my implementation is thread safe: ...
12
votes
3answers
1k views

Java and C++ stack implementations with dramatically different performance

I'm developing a small programming language for use in any project I have where I feel a small scripting language could be used well. I've written two emulators for the language, one in C++ and one in ...
3
votes
1answer
142 views

C-style generic stack implementation in C#

I saw a nice generic stack implemented in C, in Stanford's CS107 Programming Paradigms course, so I tried to rewrite it in C#: ...
6
votes
3answers
199 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. ...
5
votes
1answer
1k views

Sort a stack in ascending order

Sort a stack in ascending order. You may only use one additional stack to hold items. Any comments on my solution? Worst case complexities: Memory complexity: O(n) Runtime complexity: O(n^2) Also, ...
2
votes
1answer
292 views

C++ program that recognizes a context-free language

This program (C++) was for a class project. A program that recognizes a given context-free language by implementing a pushdown-automaton (PDA). The PDA recognizes the following language: S → $T$ ...
3
votes
1answer
231 views

Fully Generic C++ Stack Implementation Without Lists, Arrays, or Vectors

I'm trying to write a fully generic Stack in C++. I'm not sure if this is the best way to do this. Right now I know that the Pop method needs improvement since ...
7
votes
2answers
624 views

Implementing a stack and using it to print alternate elements in reverse

Challenge: Implement a stack interface. Specifications: The interface should have ‘push’ and ‘pop’ functions. Your task is to ‘push’ a series of integers and then ‘pop’ and print every ...
3
votes
1answer
110 views

3-stack implementation with a single array

I'm teaching myself data structures and would really appreciate some feedback on my stack implementation. A couple of things I'm not sure if I should be doing: creation of the array and pointer ...
5
votes
3answers
2k views

Stack Implementation in Python

I have written a simple stack implementation and would like some feedback as to what I could improve in my code and coding practices. ...
2
votes
4answers
241 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. ...
1
vote
1answer
78 views

Python script to convert hierarchical JSON to LaTeX itemize

I have the following JSON: ...
4
votes
1answer
138 views

Stack with Array

Just coded up a simple Stack using an Array in Java for practice. Other than the lack of JavaDoc (still need to learn that part), did I cover all the bases? ...
1
vote
1answer
60 views

Make a new design of Stack with a new function

I am doing some coding exercise, and I am not sure if I have met the requirement. Can someone help me to figure it out? How would you design a stack which, in addition to push and pop, also has a ...
5
votes
1answer
77 views

Popping from a list in state while a condition is true

I'm dealing with data that stores its state as a String, treating the string like a stack. I also have to combine that with error handling. To that end, I'm using ...
6
votes
1answer
197 views

RoundStack Implementation

I just recently made an attempt at implementing what I have been led to understand is called a RoundStack, simply meaning contrary to .NET Stack's default behavior ...
3
votes
2answers
364 views

Stack Implementation

I would like comments on my implementation of a stack: ...
2
votes
3answers
119 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 ...
4
votes
3answers
187 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 ...
5
votes
2answers
569 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 ...
1
vote
1answer
52 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 ...
4
votes
2answers
131 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? ...
3
votes
3answers
485 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? ...
0
votes
1answer
2k views

Implementing a stack using a simple array, dynamic array and linked list

I have implemented a stack using simple array, dynamic array and linked list. I am requesting a review of this code. Interface for stack: ...
5
votes
2answers
340 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 ...