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

0
votes
1answer
62 views

Sort a stack using Java

This is my attempted solution to cracking the coding interview exercise 3.5. Looking for any feedback on coding style or the algorithm anywhere I can improve really. The problem specification is as ...
3
votes
2answers
32 views

Stack based non-recursive Fibonacci - Go implementation

The following function computes a the last element in a Fibonacci sequence in Go language. ...
7
votes
2answers
68 views

Python unit testing for a Stack data structure

I am completely new to unit testing. I read this chapter in Dive Into Python 3, and decided to give it a try on a basic data structure: a stack. Here is the stack code (taken from "Problem Solving ...
6
votes
1answer
36 views

Balancing Brackets Algorithm: Stack Data Structure

I am currently refining my understanding of data structures and as such, decided to implement a popular application of the Stack. Below you will find my implementation of the Balancing Symbols ...
1
vote
2answers
65 views

Implementing a queue using three stacks

This is just for fun so you will see tons of print statements for trouble shooting. I was hoping on slimming this down some and gain new ideas on what I have. This was a challenge question in a class ...
3
votes
4answers
110 views

Stack, using linked list, for parser

I have recently been trying to build a parser. After a month of trying and getting nowhere fast I decided, like I should have at begining, to research how parsers work and what they do. After a ...
2
votes
2answers
61 views

My own Stack Implementation in Java

Please review my Stack implementation and let me know if you have any suggestions. ...
2
votes
1answer
36 views

Implementation of the Stack data structure using a linked list in C++

I'm currently working on implementing overloaded operators for simplifying pop() and push() operations. Check out the ...
4
votes
3answers
518 views

Stack implementation with StackInterface

The code that I wrote is as follows: ...
1
vote
1answer
73 views

Stack which finds the minimum element

Write a program to implement stack which implements min a method which gives the minimum element below the top element in the stack. ...
0
votes
2answers
54 views

Basic Array based stack in java

Here is an array based stack. I tried to implement this basic stack from memory. I want to make sure it is correct. ...
1
vote
1answer
42 views

Check whether a given sequence can be rearranged using a stack

Working on a problem, for a given input sequence to a stack, check whether it could produce (using stack push/pop operations) the output sequence. For example if input is ...
6
votes
1answer
121 views

Implement 3 stacks using a single array in C++

One of the questions that is presented in Chapter 3 for Cracking the Coding Interview is this: Describe how you could use a single array to implement 3 stacks I'...
2
votes
1answer
95 views

Follow up: Implementation of a generic Stack in C++

This question is a follow up to the question posted here. From the answer in that question, I've improved my implementation and would like another code review. I've made a myriad changes including ...
3
votes
1answer
39 views

Stack implementation in Python 3

I'm learning Python by implementing commonly used data structures. My primary language is Java, thus would like to know if I'm being Pythonic enough. Any means to better up will be appreciated. ...
-1
votes
1answer
88 views

Implementation of a generic Stack in C++ [closed]

I've implemented a generic Stack in C++. I would like a code review in regards to my code, especially on whether or not my implementation satisfy the following 4 ...
1
vote
1answer
69 views

Stack implementation with exceptions [closed]

I would like to know if this is a great stack implementation. I created my own exception. Was that a bad idea or unnecessary? Should I have just thrown a IndexOutOfBounds exception instead of my own. ...
4
votes
2answers
79 views

Proper Stack Implementation

I want to know if this stack is implemented properly. Previously I was told a Linked List contains an inner class that represents a node and the outta class that represents the structure. Does that ...
2
votes
1answer
57 views

Stack implementation with shared_ptr C++11

stack.hpp ...
6
votes
1answer
58 views

Managing a programmatically accessible stack trace

VBA has a call stack... but there's no programmatic way to tap into it, which means in order to get a stack trace for a runtime error, one has to manage it manually. Here's some example code that ...
4
votes
2answers
84 views

Designing stack and queue from scratch in C

As a beginner and curious guy I'm interested in implementing data structures and algorithms from scratch. Here's my implementation of Stack and Queue, the most fundamental data structures. Are ...
4
votes
2answers
92 views

Stack implementation in ES6

Finally happy to see that now we can have iterators and generators. I also need to try to have private properties too so that we have well encapsulated data structures and I see that there are Proxies ...
4
votes
1answer
80 views

Implement a queue using two stacks

I tried to implement a queue using two stacks. I saw there are questions about this topic, but in my example, I used build-in stack from java. My question is, can someone give me some advice to make ...
5
votes
2answers
164 views

Poisonous Plants

I have solved the following problem. My code works but Hackerrank says that I can do faster: There are plants in a garden. Each of these plants has been added with some amount of pesticide. ...
2
votes
2answers
65 views

Finding the Least Common Ancestor of a Binary Tree

Input a binary tree (the root node) and 2 other nodes that need to be assessed for finding the least common ancestor (LCA) Code: a. Finding the nodes first with either ...
4
votes
2answers
94 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
75 views

Stack from Linked List

I have written a program that takes a linked list and then converts it to a stack. I would like a code review for my program. Thanks in advance. Stack.java ...
2
votes
0answers
55 views

Improving time efficiency of finding maximum area rectangles in a histogram

Here's my solution but I am looking for ways to improve the time complexity of solution. Also this question is categorized as being solved by stack so I would like to know how to approach it using ...
0
votes
1answer
48 views

Stack that does Push, Pop and Median in O(1)

Here are two implementation of a stack that does Push, Pop and Median in O(1). Invite comments on complexity and betterment. Option - 1 ...
2
votes
4answers
186 views

Reverse Polish Notation Evaluation in Java

I would like to hear feedback about my code both in term of improving efficiency if possible or using other data structures. Also go ahead and let me know about code styles/patterns. ...
3
votes
1answer
47 views

Queue implementation using two stacks

Here's my code and I want to know if there's a better method for doing so. While the question has stated two stacks I wonder if we could do only with one as well? ...
2
votes
1answer
60 views

Building a Stack with C structs

After reading the book from which this example is from I started using APIs like this ...
4
votes
3answers
125 views

C++ Dynamic array based stack

I have implemented a dynamic array based stack. Can someone point out any pitfalls or things that can be done better? MyStack.h ...
3
votes
1answer
71 views

Sort stack using two stacks

My program is supposed to sort a stack such that the smallest item are on the top. I can use a temporary stack, but you may not copy the elements into any other data structure. The program works ...
1
vote
0answers
45 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
65 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....
4
votes
1answer
74 views

Sort a stack in descending order

Maintain current element as the top element in the input stack. Pop all the elements on the ordered stack which are greater than the current element and push them in to the input stack and maintain a ...
2
votes
0answers
36 views

Stack based esoteric language interpreter in Ruby

For a while now, I've wanted to write a stack-based "Turing-tarpit". This is the perfect excuse to learn Ruby, which I have never used before, so I wrote Brain-flak. The language only uses these ...
6
votes
2answers
81 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. ...
2
votes
2answers
62 views

A stack optimized for filter queries, written in the C++ preprocessor

Given a stack with N elements and a query Q, we need to find all elements of stack for which ...
6
votes
2answers
299 views

Find minimum node in Linked-List

I wrote a method that will return the minimum element in a linked-list that operates in O(1) time. I tested and everything works fine. However, I was wondering if there is anything that I can do to ...
-1
votes
1answer
75 views

C stack for Linux and BSD

My stack uses char data and is not tested. I use it to save command in a unix pipeline for my own POSIX shell. Maybe you can find a bug or a possible improvement. ...
2
votes
1answer
109 views

Dynamic array stack and bag implementation

I've have methods for a stack and bag using a dynamic array in C. As far as I can tell everything is implemented correctly, but I'm wondering what I can do to improve this code. dynArray.h ...
5
votes
1answer
66 views

Stack implementation using a growing array

I'm working through Sedgewick's Algorithms book for fun and educational purposes. I am implementing a simple Stack<T>, using ...
4
votes
1answer
120 views

Balanced parenthesis in Ruby

I'm solving the "Balanced Parenthesis" problem in Ruby, and I came up with this solution. ...
3
votes
2answers
86 views

Stack and Queue implemented with a LinkedList

I am looking for feedback on my implementations of Queue, Stack, and LinkedList using Java ...
9
votes
3answers
196 views

Fuzzy Octo Guacamole interpreter

This is my code that interprets my own golfing and esoteric language, Fuzzy-Octo-Guacamole. It has 2 stacks to store information in, and various operations can be performed on each stack, or both at ...
3
votes
2answers
158 views

Comparing a string using a stack

Let L be the language defined as follows: The words are made up of strings of a’s followed by b’s. The number of a’s is always equal to the number of b’s. Examples of words that belong to ...
1
vote
2answers
229 views

Fixed-length Stack in Java

I implemented a fixed-length stack in Java for use in my fractal generator program, an RPN calculator and my esolang interpreter. This is a generic stack, and goes over and above the call of duty in ...
1
vote
1answer
95 views

Java Stack Implementation with Generics

I've written an implementation of a Stack data structure using a linked list. Stack.java ...