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

5
votes
3answers
67 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
24 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
47 views

Queue/stack/node class Implementation

Below there are 3 short header files for queue, stack, and node implementation. I do ...
1
vote
1answer
38 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 ...
4
votes
1answer
43 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
1answer
35 views

How to delete the elements from multiple array , so that the sum of remaining elements of each array is equal [closed]

I need to delete elements from 3 arrays(starting from index 0) and keep doing it until the sum of remaining elements in each array is equal . ...
0
votes
2answers
63 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 ...
3
votes
2answers
122 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
856 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
91 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 <...
5
votes
2answers
102 views

Stack based recursive arithmetic expression parser

I recently started to learn C++ and came across this problem in a book "Object Oriented Programming in C++" by Robert Lafore. The author has a program in the book which creates a Parser. I found a ...
5
votes
2answers
69 views

Stack and Queue Linked List Implementations

I'm relatively new to C as a language, but I wouldn't call myself a beginner. That being said, I don't believe my C "coding style," so to speak, is particularly developed. Also, I'm new to error ...
1
vote
4answers
199 views

Split a long string using recursive function

I have executed a program which reads long string and divide the string on basis of specified input. Well I am getting the correct output but would try it to be more efficient and readable. Opinions ...
3
votes
1answer
72 views

My Stack implementation in Java

I have started learning data structures and have implemented my own stack implementation: ...
0
votes
0answers
106 views

Transactional Stack

It is about Stack of numbers, that can have transaction. If you begin transaction, you need to commit it in order to actually add numbers to stack. Transactions can be nested. ...
2
votes
1answer
161 views

Binary tree inorder traversal (iterative solution)

Problem statement Given a binary tree, traversal the binary tree using inorder traversal, so the left child is visited first, and then node and then right child. Write an iterative solution as a ...
10
votes
4answers
357 views

Stack data structure implementation

I have implemented in C# a stack data structure, without using any existing C#/.NET containers (data structures). I have used TDD technique to implement this requirements, so you can find tests, too. ...
6
votes
1answer
180 views

Valid Parenthesis

Recently, I've solved the "Valid Parenthesis" problem on LeetCode: Given a string containing just the characters '(', ')', <...
2
votes
0answers
52 views

Pushdown-stack: Test if a pop order is legal or not

I'm currently working through "Algorithms in java" by Robert Sedgewick (3rd edition, in german) on my own and am trying to solve one of the exercises there. The exercise asks to develop and ...
9
votes
3answers
1k views

Finding the maximum element of a Stack

I have been solving this problem of Hackerrank recently .. https://www.hackerrank.com/challenges/maximum-element A little bit about the problem You have an empty sequence, and you will be given N ...
5
votes
2answers
70 views

Linked deque implementation in C

I wrote a deque implementation in C for storing char *. It uses a doubly linked list, but I'm calling it a deque since it can only push/pop from the head and tail ...
5
votes
2answers
131 views

Is there a circular reference in a set of template substitutions?

I have a configuration engine that allows the user to specify a dictionary with text templates (read from a JSON file) where each placeholder like {x} can be ...
5
votes
2answers
167 views

Object pool pattern for asynchronous socket operations

I have written my own object pool class called ObjectPool<T> which uses SpinLock and ...
4
votes
1answer
36 views

FixedStack of the Container hierarchy in Java

Introduction/Disclaimer This is a project for educational purposes. I'm not intending to replace the "award-winning" Collections Framework in java.util. I'm just ...
-3
votes
1answer
109 views

Implement stack class from scratch for a h-rank challenge

Write a stack class from scratch to house integers using any programming language of your choosing that implements the following methods: ...
0
votes
1answer
131 views

Concurrent Stack with blocking and non-blocking methods

I wrote it this just for learning. Is there holes at this code? ...
1
vote
1answer
121 views

Concurrent blocking stack

I just want to train before interview. I googled concurrency interview questions and one of the question was write concurrent ready stack. ...
4
votes
2answers
113 views

My implementation of Stack and Queue with Array without help of library functions

I am new to Java and am trying to learn coding. Here is my implementation of a stack and a queue without the help of library functions. Please provide your suggestions on design, coding style and ...
5
votes
1answer
64 views

Concurrent stack in C - follow-up

This is a follow-up question to Concurrent stack in C The pop function not just removes the top element from the stack, but also returns it. If a pthreads call ...
3
votes
2answers
73 views

Create a stack implementation that handles the multi thread scenario

MyStack.h @interface MyStack : NSObject - (id)pop; - (void)pushObject:(id)object; @end MyStack.m ...
6
votes
2answers
127 views

Concurrent stack in C

(See also the follow-up question.) I was in the mood for pthread.h and decided to write a concurrent stack data structure. My requirements: the stack has maximum ...
2
votes
2answers
111 views

Stack abstraction

Here is the Stack abstraction: ...
5
votes
2answers
83 views

Stack class in Ruby to calculate maximum number, get the average, pop, push

Is the class optimized enough to accept 1 million items in the stack? ...
8
votes
6answers
250 views

Implement queue using two stacks

Although it's a well-known algorithm, I thought to implement it from the perspective of a coding interview. I want to know if I can improve my code somehow. So, given the time constraint, is this a ...
5
votes
2answers
123 views

Linked-list-based stack and queue

This is my first attempt at building a linked-list-based stack and queue. It is the result of ~90 minutes of trying to implement some of what we're being taught in Algorithms class. I would like ...
5
votes
1answer
62 views

Basic linked list stack implementation with go

Here goes my first stack implementation with go New to the go language and it's been ages since I implemented a stack Would love to discuss the data structure implementation itself and how "goish" ...
3
votes
3answers
573 views

Circular shift string

So,basically I am working on an algorithm for circular shifting a string upto a position.There are two parameters required here. String of text to shift Number of shifts required. For example: <...
0
votes
1answer
223 views

Sort Stack using just an additional stack

The problem is from the cracking coding Interview programming book. The problem is that: Sort Stack: Write a program to sort a stack such that the smallest items are on the top. You can use an ...
10
votes
3answers
1k views

StackList<T> implementation

I needed a structure that works really similar to the predefined Stack<T> but with a few extra functionalities. Examples include getting the index of value in ...
3
votes
3answers
600 views

C++ implementation of Hackerrank's “Maximum Element in a Stack”

I just attempted the Maximum Element Challenge on Hackerrank. This question has been posted before in swift Swift Hackerrank Maximum Element in a Stack but it has attracted low views/no answers. ...
3
votes
1answer
70 views

Algebraic Effect Monad to separate pure and impure code

I want to write my C# code in a way which makes effects (state, I/O, etc) explicit in the type signature. I have started to understand monads, and have some acquaintance with algebraic effects, though ...
3
votes
1answer
59 views

Stack implementation, array-based

My understanding is that Stack possesses LIFO property. And, based upon that I have written the following program: ...
3
votes
1answer
139 views

Matlab tic and toc commands implemented in C++

I need to time a few functions that I'm implementing, so I decided to implement a way of timing even multiple or sub calls based on the stack data structure and on the ...
6
votes
2answers
1k views

Very simple stack in C

I'm starting to learn C and thought it would be a good idea to try and implement some data structures. I started with a very simple stack and would like to hear some opinions. Stack.c ...
-1
votes
1answer
45 views

Trying to build a bare metal stack on the stack [closed]

I'm trying to implement a stack data structure, but not on the heap but using the stack. Also not using any Node or Element struct but raw ints. Is this feasible? This is my code (with debug printfs) ...
5
votes
4answers
1k views

Memory leak in stack

I'm implementing a stack by C++ and here I think it has memory leakage problem: in Stack::peek() and Stack::pop(), where I ...
0
votes
1answer
229 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
95 views

Stack based non-recursive Fibonacci - Go implementation

The following function computes a the last element in a Fibonacci sequence in Go language. ...
8
votes
2answers
232 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
98 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 ...