Skip to main content

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
3 votes
2 answers
892 views

Using the stack algorithm for parenthesis matching

I have used Stacks to check for brackets mismatch. (Parentheses matching problem using Stack algorithm) Any suggestions on how to improve the code? I have tried various examples and it works ...
2 votes
2 answers
129 views

Stack Linked list based implementation in C++

This is my second implementation of the Stack in C++. I already implemented it as an array-based here. I need a review for it to improve it and improve my coding skill. I also will put this ...
2 votes
1 answer
62 views

Simple Stack and Deque implementation (v2)

My previous post: Simple Stack and Deque implementation I have implemented 2 classes for my project similar to stack and deque. This is my second attempt to get advice and evaluation of my code. Maybe ...
1 vote
1 answer
107 views

Simple Stack and Deque implementation

I implemented a single-linked and double-linked lists (like stack and deque). I would like to receive your feedback on improving the code or maybe some comments. I'm learning C++ for the third month. ...
4 votes
4 answers
1k views

Stack - implementation in Java

I implemented a stack data structure without using any libraries or Java API code. ...
4 votes
2 answers
482 views

naive C++ stack template class

I just learned Adapter Pattern, and I have used STL for some time. I know that the std::stack is a adapter for sequence container (say, ...
2 votes
2 answers
102 views

Generic stack implementation (revision)

The below post is a follow-up of Generic stack implementation. Below follows a header-only implementation of a generic stack (inspired by stb-libraries, following these guidelines: stb-howto.txt). ...
3 votes
1 answer
214 views

Generic stack implementation

The provided code (a header-only library inspired by stb libraries] defines functions for creating a stack, pushing elements onto the stack, popping elements from the stack, peeking at the top element ...
11 votes
5 answers
2k views

Detecting balanced parentheses

Objective: Given a string s containing '(', ')', '{', '}', '[', ']' (and other characters), determine if the input string is valid. An input string is valid if: ...
3 votes
1 answer
447 views

C++ Updated Stack Code

The original question can be seen here: Stack implementation in C++ using linked list Changes (with the help of Martin): Added copy constructor and assignment operator overload Changed return type ...
6 votes
2 answers
481 views

Stack implementation in C++ using linked list

I am learning C++ and I made a simple stack class using a (reversed) linked-list to test my knowledge. Are there any problems with the following code, or any suggestions to improve it? I want to ...
3 votes
2 answers
113 views

Functions to simplify printing strings and numbers in amd64 Assembly

I'm new to Assembly, and this is my very first "project" in Assembly. I wanted to store data (numbers) on the stack, then access and display them. Eventually, this "experiment" of ...
1 vote
4 answers
2k views

Exercise: Design a Stack

Exercise: Design a Stack A Stack is a data structure for storing a list of elements in a LIFO (last in, first out) fashion. Design a class called Stack with three methods. ...
3 votes
1 answer
161 views

`strdup` re-implementation in assembly

I am posting a message here because I am new to assembly programming. My goal today was to re-code strdup in assembly, so to save my first parameter which is a ...
14 votes
3 answers
2k views

Stack Implementation in C++ with Exceptions

Appreciate your thoughts and feedback... Stack.h ...
0 votes
4 answers
812 views

Stack using doubly linked list

I have implemented my stack based on a doubly linked list. The code is tested and works; however, I am interested in any improvement ideas. ...
0 votes
3 answers
163 views

Simple stack of integers

I've a simple push/pop implementation in my program: ...
0 votes
3 answers
202 views

Delayed, concurrent event stack in Java

(See the next iteration: Delayed, concurrent event stack in Java - follow-up ) Motivation I was confronted with a task of having "message events" for a GUI program. The use case is as ...
0 votes
1 answer
67 views

Delayed, concurrent event stack in Java - follow-up

I have slightly refactored the Delayed, concurrent event stack in Java. Now it looks like this: DelayedEventStack.java ...
4 votes
1 answer
158 views

Queue implemented using two stacks in Swift

I need your expert opinion! In fact, for a Leetcode Problem, I had to code a queue using 2 stacks. It's shown just below and functions well. It is a pretty simple code with peek, pop, push, etc. ...
2 votes
0 answers
67 views

C Finding strongly connected graph components in linear time using Kosaraju's algorithm

I followed this algorithm to find strongly connected graph components in C and this code works (I think ... maybe there are bugs I am not aware of). I am wondering can I please get some feedback? ...
2 votes
3 answers
1k views

Check if parentheses are balanced using a stack implemented with a linked list

Problem: Stacks can be used to check whether the given expression has balanced symbols. This algorithm is very useful in compilers. Each time the parser reads one character at a time. If the character ...
2 votes
0 answers
117 views

Monotonic stack - complexity analysis

I tried following the official solution of LC975 (https://leetcode.com/problems/odd-even-jump/), using a monotonic stack - i.e., I reimplemented their solution (Approach 1) from python in C++. TLDR ...
4 votes
3 answers
2k views

Infix to Postfix Converter in C++

I have written a program to convert an infix expression to postfix with the help of infix2postfix() function. Please review my code and suggest ways to make it ...
2 votes
2 answers
298 views

Stack array based implementation in C++

I wrote my implementation to Stack array based. And I need a review for it to improve it and improve my coding skill. I also will but this implementation on my GitHub account. One more thing: I am not ...
3 votes
2 answers
4k 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 ...
2 votes
1 answer
85 views

A (Sort of) Generic Stack Implementation in C using Macros

I spent some time implementing a generic stack in C using macros. Apart from general bugs and bad practices in my code, I was wondering about the viability of an implementation like this that uses ...
25 votes
3 answers
9k views

Leetcode: Valid parentheses

Leetcode: Valid parentheses Given a string containing just the characters (, ), {, ...
4 votes
3 answers
7k 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. ...
2 votes
2 answers
75 views

Basic Stack Operations using Linked List in C

I have made a few functions for some basic stack operations using linked lists. Please review my code and suggest some ways to increase its readability. I would also love to hear ideas on how to make ...
2 votes
0 answers
42 views

JavaScript Linter in Java

I wrote a simple Linter that checks for matching opening and closing braces for one line of JavaScript. It utilizes a stack to store opening braces found in the line, then compares the first closing ...
5 votes
2 answers
270 views

Stack implementation in C programming Language

I have tried to implement a Stack and associated functions in C, in order to understand the data structure better. Just wanted to know what do you think about my code overall. Furthermore, I am using <...
1 vote
2 answers
488 views

Leetcode - find if BST is valid or not

Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node'...
7 votes
1 answer
378 views

Pseudo-Generic Array Stack in C

I have implemented an array based pseudo-generic stack in C using macros. The code works fine for all data types. Is it a good idea to implement such a data structure using macros? array_stack.h ...
3 votes
1 answer
114 views

Generic stack data structure using linked list and smart pointers

I have decided to rewrite what I did here, following the suggestions to use smart pointers. I will rewrite the other data structures as well using smart pointers where appropriate. I just want to see ...
7 votes
2 answers
15k views

Iterating an array of nodes, each of which can have children

I've written some C# code to iterate through a Node[], listing all of its nodes in order (i.e. child elements are listed immediately after the parent). Each ...
3 votes
3 answers
4k views

HackerRank (Stacks) - Maximum element solution gets a timeout

Apparently my solution is really slow. Can someone help me with why my solution passes a little over half the test cases for this question? Here is my solution: ...
7 votes
1 answer
6k views

Optimizing Efficiency in a Stack

I'm solving a problem on HackerRank where I'm required to implement a simple stack. It's passing all the tests except for the last 4 where it fails due to surpassing the time constraint of 10s. ...
5 votes
3 answers
6k views

Balanced parenthesis in Ruby

I'm solving the "Balanced Parenthesis" problem in Ruby, and I came up with this solution. ...
3 votes
1 answer
549 views

Finding the minimum element of a stack of numbers

As part of an online programming challenge, I wrote a program that implements a stack of integers, supporting adding and removing elements, finding the last inserted element, and the minimum element. ...
1 vote
1 answer
59 views

How can I make this check balanced parenthesis implementation more concise and efficient?

I'm new to common lisp. I basically translated a procedural implementation of balanced parenthesis using a stack to common lisp. How can I make my implementation more lispy? ...
5 votes
2 answers
1k 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 ...
-1 votes
2 answers
100 views

Optimization suggestions for my Stack [closed]

stack.hpp ...
3 votes
2 answers
109 views

Stack API for generic values

I'm trying to create a stack library from scratch. It stores generic elements which are passed in void* pointers. This is the defined structure: ...
2 votes
1 answer
612 views

Evaluating postfix expression on multidigit numbers

This is my solution for evaluating postfix expression using a stack. It does work on multidigit numbers, the problem I was struggling with last time. Now it works completely fine. This is the stack ...
3 votes
4 answers
370 views

Passing Programs To A Stack Machine Implemented In C++

I'm learning C++ by implementing a previous project I did in Python. This is a simple stack machine which evaluates mathematical expressions, e.g. pow(9, 12). The code to run this on the stack ...
3 votes
2 answers
186 views

Check for max value in stack

Got this problem in a coding interview - Get the max value of a stack in O(1). The stack contains numbers only. Please review my solution. ...
8 votes
2 answers
2k 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'...
4 votes
2 answers
1k views

Stack Implementation in JavaScript

I am learning data structures and below is my implementation of a stack in JavaScript. I didn't want to use built in functions for an array because in JavaScript that would be too easy, so I made my ...
3 votes
2 answers
1k views

Python stack and queue classes, implemented using lists

I have made a stack and queue implementation with OOP in Python (sorry for variable names) . It is made from scratch. I just watched a video how these two things work. I am still trying to improve in ...

1
2 3 4 5
9