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

2
votes
2answers
43 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 ...
3
votes
1answer
59 views

Queue Using Stack java implementation

Implemented this solution for the problem. Feedback and review if this can be improved in an way. Appreciate your help. ...
3
votes
1answer
66 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 ...
1
vote
0answers
39 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
39 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
152 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
41 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? ...
1
vote
1answer
53 views

Building a Stack with C structs

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

C++ Dynamic array based stack

This is my first post so if I am doing something wrong in the post please let me know. I have implemented a dynamic array based stack. Can someone point out any pitfalls or things that can be done ...
3
votes
1answer
50 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
43 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
63 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
66 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
33 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
70 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
2answers
136 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
69 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
66 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
62 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
81 views

Balanced parenthesis in Ruby

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

Stack and Queue implemented with a LinkedList

I am looking for feedback on my implementations of Queue, Stack, and LinkedList using Java ...
8
votes
3answers
171 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
75 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
130 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
80 views

Java Stack Implementation with Generics

I've written an implementation of a Stack data structure using a linked list. Stack.java ...
-2
votes
2answers
100 views

Checking for matching delimiters using multiple stacks or counters

I know my algorithm is very naive and slow for this problem. I would like to learn how to improve upon it? ...
0
votes
1answer
54 views

Custom concurrent stack implementation in Java

I don't want to use synchronized for sizeof method, any suggestion to implement the method thread safe? ...
2
votes
2answers
72 views
2
votes
2answers
53 views

Program looks for correct balance of ( [ and { in expression

I'm still new to programming. (First exposure was school about a year ago), and for some reason this problem really gave me a lot of problems trying to solve it. Can you help me understand what I ...
3
votes
1answer
118 views

Tail-recursive call vs looping for a Poker app

I'm developing a Poker app. It is almost done, and I'm looking for improvement. One of the things I wonder is whether I should change how I perform iterations. I currently iterate by using tail-...
3
votes
3answers
107 views

Sort stack in ascending order

I am using two more helper stacks to sort. Kindly suggest improvements in terms of space and time. ...
1
vote
1answer
42 views

Implement MyQueue using two stacks

I am taking a helper stack, which is used during dequeue. Kindly suggest improvement or some solution with less complexity. ...
10
votes
2answers
897 views

Stack having push, pop and return min in O(1)

I am using a class which is taking care of minimum value so far. Please let me know of any improvements or suggestions. ...
4
votes
1answer
206 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 ...
4
votes
1answer
56 views
8
votes
1answer
68 views

Implementing Multi-File Programs in Vitsy

I'm the proud owner of the Vitsy programming language, which I've been working on for some time (except recently, because high school). It's only been used in PPCG so far, but I hope to expand it to ...
4
votes
2answers
136 views

Implementation of stack

Task: Create a class RPNStack which represents a stack of objects of type Node. Class RPNStack contains only one private field top of type Node. Objects of type Node represent data that are ...
3
votes
1answer
43 views

Simple stack structure in C

I just started to learn C, and for practicing, I tried to implement a simple stack data structure, and I want to know if I'm making any mistakes, or how could I improve it: My stack.h: ...
3
votes
2answers
83 views

C Stack data structure

I have implemented a Stack data structure in C and I would like to know if there is something that could be improved. Stack using linked list: ...
4
votes
2answers
183 views

Sort a stack of numbers in ascending order only using push

I have a stack of numbers ranging from 1 to 1 million representing a pile of numbered DVDs. Given the stack in random order I am to sort the stack by only taking an element from the stack and push it ...
5
votes
2answers
108 views

Given a path to a directory, print the path to the biggest file in it

Here is my code. I simulated a stack rather than used some regular recursive algorithm because I needed to keep track of two variables: the path to the biggest file and its size. Besides I wrote a few ...
2
votes
1answer
102 views

Mutable stack in Racket

I'm learning Racket and have implemented a mutable stack, which is just a bunch of wrappers around an underlying struct containing a size and buffer list (so it's ...
0
votes
2answers
150 views

Infix to postfix implementation using a stack

I have implemented a "infix-to-postfix" function that takes as input a list representing the parsed expression, resulted from applying a certain regular expression to an expression, and I would like ...
3
votes
2answers
106 views

Sorting a Stack in ascending order

Here's my implementation of sorting a stack in ascending order. The problem statement is as follows : Write a program to sort a stack in ascending order (with biggest items on top). You may use ...
1
vote
2answers
177 views

Traversing a stack in my DFS algorithm for finding a path in a maze

I am trying to get this code running as fast as possible when traversing through my stack of my DFS currently the input files are like so: ...
0
votes
1answer
44 views

LinkedListy-Stack

I came across this interesting question while reading 'Cracking the coding Interview' and came up with a simple implementation. Any suggestions are welcomed. Imagine a (literal) stack of plates. ...
3
votes
2answers
112 views

C++ Stack implementation using std::list

I have the following 'interface' to the C++ std::list and I was wondering how I could make it go faster. In particular, it needs to be able to evaluate up to two ...
10
votes
2answers
148 views

SortedStack implementation in Java

This is a data structure that supports the push(), pop() and isEmpty() operations and ...
6
votes
3answers
558 views

Simple Stack Implementation in C

This is my implementation of the stack data type in C language. It is static meaning it does not grow in size. Any suggestions or feedback would be much appreciated. ...
7
votes
2answers
231 views

Stack implementation in Java

Here's my implementation of a Stack in Java, all feedback welcome. ...