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
2
votes
1answer
58 views

JavaScript Queue Attempt #2

This is a follow-up review to JavaScript queue implementation using linked list I've run the code through a linter, fixed every style error, added const where it ...
9
votes
2answers
2k views

A counterexample in balanced parentheses

In this program I had to analyse if the parenthesis given are well balanced. For instance, input (()) is correct and input ())(()...
1
vote
1answer
444 views

Analyzing an arithmetic expression using stacks

I'm looking for some constructive (harsh) criticism of a homework I've done (the code works fine). Also Is there a better/another way to solve the exercise? Exercise: Read an arithmetic expression ...
3
votes
1answer
64 views

A C stack with minimum and maximum values

I have this C stack implementation that knows its minimum and maximum values: minmax_stack.h ...
4
votes
3answers
146 views

Implementation of a simple stack with min method

The problem statement: Implement a stack which has push and pop method and also min method whereas min method has \$O(1)\$ complexity. From an interview standpoint, what mistakes would you point ...
4
votes
2answers
647 views

JavaScript animation effect stack

I am building a library that uses animations in a canvas. I need to apply effects to some objects in the canvas and I came up with an effect stack that contains each effect to be executed on a ...
6
votes
3answers
88 views

Minimal stack from unsigned int to track boolean values wtih bits

This grew out of a need to track sequential ctrl+shift+Left/Right-arrow keypress events on a gtk editor. It is a small stack implementation for boolean values (for <...
3
votes
1answer
1k views

Stack - Implemented as Singly Linked List

Note: I do know that Python libraries provide a Linked List and Stack. This implementation has been done to practice ...
10
votes
1answer
2k views

Dynamic stack C implementation

I'm a C beginner. I'm studying and implementing some data structures. I'd like to get feedback. This is a stack implemented with an dynamic array. In main there ...
7
votes
5answers
903 views

Java Stack Implementation

I'm looking for a code review on my Stack Implementation in Java. Specifically I am looking for correctness, style, and efficiency. Thank you! ...
5
votes
3answers
2k views

Implementation of Stack using Linked List

Please review my code and help me to improve it. I have written this code using template. Can I use more C++11? Is using top in this code is necessary? ...
1
vote
1answer
4k views

Stack implementation using nodes

Purpose Implement a Stack with push, pop, and peek ...
7
votes
3answers
2k 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
1k 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
2k views

Queue/stack/node class Implementation

Below there are 3 short header files for queue, stack, and node implementation. I do ...
4
votes
2answers
2k 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 ...
5
votes
2answers
701 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
2answers
134 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 ...
5
votes
2answers
10k 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
2k 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
10k 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 <...
6
votes
2answers
703 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 ...
6
votes
2answers
212 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
2k 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
175 views

My Stack implementation in Java

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

Valid Parenthesis

Recently, I've solved the "Valid Parenthesis" problem on LeetCode: Given a string containing just the characters '(', ')', <...
2
votes
0answers
105 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 ...
8
votes
4answers
5k 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
921 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
195 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
712 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
42 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
172 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
3k 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
507 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
146 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
133 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
100 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
573 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
3answers
152 views

Stack abstraction

Here is the Stack abstraction: ...
5
votes
2answers
153 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
870 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
204 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
10k 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
553 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 ...

1 2
3
4 5
8