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.
-5
votes
0answers
24 views
What is the problem in the Balanced Brackets solution with Stacks? [on hold]
I have solving this problem in HackerRank and this is my solution:
...
6
votes
2answers
69 views
Concurrent stack in C
I was in the mood for pthread.h and decided to write a concurrent stack data structure. My requirements:
the stack has maximum capacity,
pushing an element,
...
2
votes
2answers
106 views
4
votes
1answer
50 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
152 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 ...
4
votes
2answers
60 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
42 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
93 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
58 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
346 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
0answers
50 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
46 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
63 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
993 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
38 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
104 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
64 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
107 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
61 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
76 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 ...
3
votes
4answers
122 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
76 views
My own Stack Implementation in Java
Please review my Stack implementation and let me know if you have any suggestions.
...
2
votes
1answer
70 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
538 views
1
vote
1answer
74 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
60 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
47 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
155 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
99 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 ...
3
votes
1answer
52 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
97 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 ...
1
vote
1answer
70 views
Stack implementation with exceptions [closed]
I would like to know if this is a great stack implementation. I created my own exception. Was that a bad idea or unnecessary? Should I have just thrown a IndexOutOfBounds exception instead of my own.
...
4
votes
2answers
83 views
Proper Stack Implementation
I want to know if this stack is implemented properly. Previously I was told a Linked List contains an inner class that represents a node and the outta class that represents the structure. Does that ...
2
votes
1answer
96 views
6
votes
1answer
71 views
Managing a programmatically accessible stack trace
VBA has a call stack... but there's no programmatic way to tap into it, which means in order to get a stack trace for a runtime error, one has to manage it manually.
Here's some example code that ...
4
votes
2answers
89 views
Designing stack and queue from scratch in C
As a beginner and curious guy I'm interested in implementing data structures and algorithms from scratch. Here's my implementation of Stack and Queue, the most fundamental data structures.
Are ...
4
votes
2answers
96 views
Stack implementation in ES6
Finally happy to see that now we can have iterators and generators. I also need to try to have private properties too so that we have well encapsulated data structures and I see that there are Proxies ...
4
votes
1answer
103 views
Implement a queue using two stacks
I tried to implement a queue using two stacks. I saw there are questions about this topic, but in my example, I used build-in stack from java. My question is, can someone give me some advice to make ...
5
votes
2answers
229 views
Poisonous Plants
I have solved the following problem. My code works but Hackerrank says that I can do faster:
There are plants in a garden. Each of these plants has been added
with some amount of pesticide. ...
2
votes
2answers
75 views
Finding the Least Common Ancestor of a Binary Tree
Input a binary tree (the root node) and 2 other nodes that need to be assessed for finding the least common ancestor (LCA)
Code:
a. Finding the nodes first with either ...
4
votes
2answers
110 views
Queue using Stack
I implemented this solution for the problem. Please provide feedback and review if this can be improved in any way.
...
3
votes
1answer
82 views
Stack from Linked List
I have written a program that takes a linked list and then converts it to a stack.
I would like a code review for my program. Thanks in advance.
Stack.java
...
2
votes
0answers
62 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 ...
0
votes
1answer
54 views
Stack that does Push, Pop and Median in O(1)
Here are two implementation of a stack that does Push, Pop and Median in O(1). Invite comments on complexity and betterment.
Option - 1
...
2
votes
4answers
260 views
Reverse Polish Notation Evaluation in Java
I would like to hear feedback about my code both in term of improving efficiency if possible or using other data structures. Also go ahead and let me know about code styles/patterns.
...
3
votes
1answer
53 views
Queue implementation using two stacks
Here's my code and I want to know if there's a better method for doing so. While the question has stated two stacks I wonder if we could do only with one as well?
...
2
votes
1answer
63 views
Building a Stack with C structs
After reading the book from which this example is from I started using APIs like this
...
4
votes
3answers
157 views
C++ Dynamic array based stack
I have implemented a dynamic array based stack. Can someone point out any pitfalls or things that can be done better?
MyStack.h
...