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.

8 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4
votes
0answers
97 views

All the paths from the root to the leaves

Given a binary tree, return all root-to-leaf paths. Example: -- 1 / \ 2 3 \ 5 Output should be: ["1->2->5", "1->3"] My approach: I walk the branches ...
3
votes
0answers
90 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 ...
3
votes
0answers
423 views

Find redundant braces in an input string

I am solving interview questions from here. Problem : Write a program to validate if the input string has redundant braces Return 0/1 : ...
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 ...
2
votes
0answers
202 views

Improving time efficiency of finding maximum area rectangles in a histogram

Here's my solution but I am looking for ways to improve the time complexity of solution. Also this question is categorized as being solved by stack so I would like to know how to approach it using ...
2
votes
0answers
64 views

Stack based esoteric language interpreter in Ruby

For a while now, I've wanted to write a stack-based "Turing-tarpit". This is the perfect excuse to learn Ruby, which I have never used before, so I wrote Brain-flak. The language only uses these ...
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. ...
1
vote
0answers
71 views

Mergesorting a stack in Java - a new algorithm

(See the previous iteration.) Now I have implemented a stack merge sort that does not have to reverse every substack after sorting it, and it allocates the two auxiliary stacks only once prior to the ...