Questions tagged [stack]

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.

Filter by
Sorted by
Tagged with
1
vote
4answers
1k 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
151 views

My Stack implementation in Java

I have started learning data structures and have implemented my own stack implementation: ...
1
vote
0answers
1k 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
3k 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
711 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
8k views

Valid Parenthesis

Recently, I've solved the "Valid Parenthesis" problem on LeetCode: Given a string containing just the characters '(', ')', <...
2
votes
0answers
99 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
4answers
4k 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
772 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 ...
6
votes
2answers
184 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
656 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
41 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 ...
-2
votes
1answer
160 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
2answers
2k 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
428 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
141 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
113 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
95 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 ...
7
votes
2answers
424 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
132 views

Stack abstraction

Here is the Stack abstraction: ...
5
votes
2answers
137 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
769 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
1k 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 ...
4
votes
1answer
159 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
8k 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
489 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
2k 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 ...
4
votes
3answers
2k 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. ...
6
votes
1answer
238 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 ...
2
votes
1answer
93 views

Stack implementation, array-based

My understanding is that Stack possesses LIFO property. And, based upon that I have written the following program: ...
2
votes
1answer
693 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
86 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
2k 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
423 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 ...
2
votes
2answers
603 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
1k 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
220 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
341 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 ...
4
votes
4answers
631 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
1k views

My own Stack Implementation in Java

Please review my Stack implementation and let me know if you have any suggestions. ...
2
votes
1answer
184 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
623 views

Stack implementation with StackInterface

The code that I wrote is as follows: ...
2
votes
1answer
453 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
461 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
67 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
791 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
129 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 ...
5
votes
1answer
2k 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
237 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 ...