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

3
votes
1answer
39 views

Stack-based mini-stack

I've created a MiniStack to assist in removing recursion from routines using a manual stack. Obviously if the stack is an object it lives on the heap and its ...
0
votes
1answer
30 views

Stack with minimum implementation [closed]

My homework is to write an implementation of a stack with minimum. Could you please tell me if my implementation is correct? And, if it is correct, how to make it better? My most concern is about the ...
6
votes
1answer
58 views

Traversal of descendants using stack [closed]

I have a type Unit which has a property ChildUnits that returns the children of the unit instance, as a ...
4
votes
4answers
212 views

LinkedList to be used in a stack or queue

This all works. Just wanted to make sure I didn't miss anything. Coming from C++ and working my way through Algorithms, 4th ed. Here is my LinkedList class: ...
0
votes
0answers
21 views

Non recursive lambda evaluator that “magically” optimizes tail recursion [migrated]

I think pasting my main method GetTermValue plus the StackFrame class and a couple of helper methods (...
6
votes
2answers
114 views

Layer Stack class to practice std::shared_ptr

The following three source files is to define and test a class StackLayer. While it was written in a need for scalable layer-based architecture design, it was also ...
5
votes
4answers
91 views

Stack implementation using only one queue in C

We start with an empty queue. For the push operation we simply insert the value to be pushed into the queue. The pop operation needs some manipulation. When we need to pop from the stack (simulated ...
4
votes
2answers
83 views

Stock span problem

The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate span of stock’s price for all n days. The span Si of the stock’s ...
6
votes
4answers
149 views

Stack with 'getMinimum' operation

Design a Data Structure SpecialStack that supports all the stack operations like push(), pop(), isEmpty(), isFull() and an additional operation getMin() which should return minimum element from the ...
4
votes
1answer
59 views

Stack with “getMiddle” and “deleteMiddle” operation

Looking for code review, optimizations and best practices. ...
4
votes
1answer
44 views

Implement stack using a linked list

I am trying to implement Stack using a linked list. Looking for code-review, best practices and optimizations. ...
7
votes
1answer
56 views

Find the Next Greatest Element

Given an array, print the Next Greater Element (NGE) for every element. The Next Greater Element for an element x is the first greater element on the right side of x in array. Elements for which no ...
6
votes
2answers
385 views

Stack challenge - improving memory consumption

I am working on this problem: Stacks Imagine, that you are employed by a software development company. You work now on the famous "D++ project", which is devoted to the creation of a new ...
3
votes
2answers
65 views

Class that implements a queue using two stacks

I am looking for a review of my code that implements a MyQueue class which implements a queue using two stacks. ...
3
votes
2answers
146 views

How is my Java code for stack implementation?

The following example shows how to implement stack by creating user defined push() method for entering elements and pop() method ...
12
votes
6answers
2k views

Implementing a Stack in Java for Technical Interview

This code is based off the Stack implementation in Chapter 3 of Cracking The Coding Interview. I modified the code to make it compile and give me the correct output. I'd appreciate any feedback on ...
0
votes
2answers
106 views

Stack implementation using a queue

I've implemented a stack using a queue. Time complexity: \$O(n)\$ - push(), where n is the number of elements in the queue \$O(1)\$ - ...
6
votes
2answers
301 views

STL Stack Implementation

I implemented std::stack from the STL for deeper understanding of the language and memory since I still am only a beginner. I implemented the stack using a singly ...
4
votes
3answers
210 views

How does this naive stack implementation look?

Consider this naive stack implementation in Elixir: ...
5
votes
1answer
131 views

Managing People in a SimCity Clone

So I am working through a few different game ideas as I learn programming, and I could definitely use some feedback on my latest project. This is a simple SimCity clone. So far I have created a City ...
7
votes
3answers
2k views

Stack implementation using an array

I am trying a stack implementation using an array. I want to know if this approach is OK or if there is a logical problem. This program is working fine. ...
3
votes
1answer
61 views

Infix to postix conversion

I'm looking for code review, optimizations and best practices. Also verifying complexity to be O(n), where n is the string length. ...
7
votes
3answers
700 views

Implementation of stack using pointers

Please review my code and let me know how I can possibly improve it. ...
19
votes
1answer
328 views

Stack implemented using linked list in x86_64 assembly

I wrote a stack implementation using a singly linked list in x86_64 assembly. This stack supports the usual push/pop operations ...
11
votes
2answers
284 views

Balanced parentheses

Given an expression string exp, write a program to examine whether the pairs and the orders of "{","}","(",")","[","]" are correct in exp. For ...
12
votes
7answers
2k views

Check for balanced parentheses

Given an expression string exp, write a program to examine whether the pairs and the orders of "{","}","(",")","[","]" are correct in exp. For ...
6
votes
1answer
132 views

Functional, but not recursive, tree traversal

To learn tree traversal i implemented os.walk, tail-recursive and stack-based. Unfortunately Python doesn't support tail call optimization. How do i rewrite my ...
4
votes
2answers
119 views

Retrieve min from stack in O(1)

I wrote some Python code to solve the following problem. I'm curious to see if someone else can find a better solution, or critique my solution. How would you design a stack which, in addition to ...
7
votes
2answers
310 views

Int stack implementation

...
3
votes
2answers
112 views

Dynamic stack in C - new version

Not long ago, I posted this dynamic stack for review. Now I wrote a new version, which is hopefully a better one. Please take a look and let me know how I could improve performance and increase code ...
5
votes
3answers
371 views

Dynamic stack implementation

I wrote this code for a dynamic stack and would like to know what would be better if done differently. It can increase memory by a percentage and/or fixed value when needed. It can also be set to not ...
-2
votes
2answers
2k views
1
vote
1answer
2k views

Postfix evaluation using a stack

I just wrote the code to evaluate a postfix expression and would like it if someone reviews it for me, it works perfectly fine but I'm having trouble adding the character "=" at the end. ...
4
votes
1answer
244 views

Multi producer/consumers lockfree stack

Can you please take a look at the following x86-64 C++ code which should implement a multi consumer/produce lockfree stack? Do you think I have missed anything? ...
4
votes
4answers
1k views

Reviewing my implementation of a stack using linked list

I have been studying data structures, and I'm new to this. Here is my code for the push and pop operations. I considered using a node=top, so that I can avoid O(n) operations for the push (i.e. ...
3
votes
2answers
127 views

Is it needed to “beautify” this Stack implementation?

I'm just learning OOP, and I have an assignment to create a Stack. I came up with the following. Is it "beauty" enough, or to "schooly". Where can I evolve? This is the class: ...
3
votes
2answers
12k views

Stack implementation using linked list

This is a working stack implementation using a linked list. I'm just curious to know if this is a good way of doing it. Any suggestions are welcome. Can we keep track of the number of elements in ...
5
votes
1answer
227 views

How is my implementation of an immutable stack?

Below is my implementation of an immutable stack class. The reverse function is trying to return a stack with all elements reversed. Is my implementation good? Maybe the reverse function can be ...
5
votes
2answers
772 views

Linked stack implementation in C++

Please feel free to be as harsh as possible. Implementation file: ...
1
vote
0answers
120 views

x86_64 assembly print integer stack allocation [closed]

I have made this simple assembly program that prints an integer in hexadecimal. It works, but I don't understand why it works with only a stack size of 15, when to print a 64 bit integer including ...
4
votes
1answer
342 views

A working stack allocator

Here's an absolutely essential piece of C++ lore, a stack allocator, that will allow you to, say, allocate strings and vectors on the stack. There are 2 stack allocators I know of, here and here. The ...
8
votes
2answers
431 views

How can this simple coroutine implementation be improved?

This is a quick and dirty implementation of coroutines that implements yield by saving and restoring the stack to and from the heap. Here's an earlier version, which does the most naive possible ...
2
votes
3answers
240 views

Review implementation of stack by using pointers in C

After I had my code for stack implementation by array reviewed I wrote stack implementation by using pointers. Here's my code. Any suggestions for improvement are welcome. I'll be adding updated ...
2
votes
2answers
644 views

Review implementation of stack by using array in C

This question has become long after many updates. Click here to go down. I have implemented stack using arrays in C. Please give me suggestions on how to improve it. The purpose of writing it is ...
4
votes
3answers
208 views

Mimicking the basic interface of std::stack

I am trying to mimic std::stack in my implementation (just the basic interface - no iterators / allocators). Since I was having trouble handling all the memory ...
2
votes
2answers
403 views

Using pointers for string manipulation

I'm taking a sentence and determining whether or not it is a palindrome. I'm doing this while learning about stacks. Is there a way I can use pointers instead of ...
5
votes
1answer
274 views

Immutable C++ stack - thoughts and performance

What are your thoughts on the fallowing immutable stack implementation? It is implemented having as a basis a C# immutable stack (where garbage collector assistance does not impose using a reference ...
3
votes
2answers
122 views

Another stack implementation (in C)

I just started learning C and the online book contained the exercise 'implement a stack'. So I did, but thought I'd put it here, because I still don't feel comfortable with pointers. So here it is: ...
1
vote
3answers
566 views

Calculating postfix notation using two forms of input

My postfix program essentially allows the user two input options to calculate a postfix equation: Confirmations after each input (after an input, the user is ask for another number, operator, or ...
6
votes
2answers
440 views

Valid Parentheses

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the correct order, "()" and "()[]{}" are ...