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.

learn more… | top users | synonyms

3
votes
1answer
25 views

Simple stack structure in C

I just started to learn C, and for practicing, I tried to implement a simple stack data structure, and I want to know if I'm making any mistakes, or how could I improve it: My stack.h: ...
3
votes
2answers
38 views

C Stack data structure

I have implemented a Stack data structure in C and I would like to know if there is something that could be improved. Stack using linked list: ...
-1
votes
0answers
31 views

Given a path to a directory, print the path to the biggest file in it - revision 2

The problem description is in the title. Revision 1 I followed the suggestions from this answer. In this revision: if (files != null) is used instead of ...
4
votes
0answers
31 views

Sort a stack of numbers in ascending order only using push

I have a stack of numbers ranging from 1 to 1 million representing a pile of numbered DVDs. Given the stack in random order I am to sort the stack by only taking an element from the stack and push it ...
4
votes
2answers
101 views

Given a path to a directory, print the path to the biggest file in it

Here is my code. I simulated a stack rather than used some regular recursive algorithm because I needed to keep track of two variables: the path to the biggest file and its size. Besides I wrote a few ...
2
votes
1answer
40 views

Mutable stack in Racket

I'm learning Racket and have implemented a mutable stack, which is just a bunch of wrappers around an underlying struct containing a size and buffer list (so it's ...
0
votes
2answers
55 views

Infix to postfix implementation using a stack

I have implemented a "infix-to-postfix" function that takes as input a list representing the parsed expression, resulted from applying a certain regular expression to an expression, and I would like ...
3
votes
2answers
67 views

Sorting a Stack in ascending order

Here's my implementation of sorting a stack in ascending order. The problem statement is as follows : Write a program to sort a stack in ascending order (with biggest items on top). You may use ...
1
vote
2answers
59 views

Traversing a stack in my DFS algorithm for finding a path in a maze

I am trying to get this code running as fast as possible when traversing through my stack of my DFS currently the input files are like so: ...
0
votes
1answer
21 views

LinkedListy-Stack

I came across this interesting question while reading 'Cracking the coding Interview' and came up with a simple implementation. Any suggestions are welcomed. Imagine a (literal) stack of plates. ...
3
votes
2answers
76 views

C++ Stack implementation using std::list

I have the following 'interface' to the C++ std::list and I was wondering how I could make it go faster. In particular, it needs to be able to evaluate up to two ...
10
votes
2answers
135 views

SortedStack implementation in Java

This is a data structure that supports the push(), pop() and isEmpty() operations and ...
7
votes
3answers
185 views

Simple Stack Implementation in C

This is my implementation of the stack data type in C language. It is static meaning it does not grow in size. Any suggestions or feedback would be much appreciated. ...
7
votes
2answers
194 views

Stack implementation in Java

Here's my implementation of a Stack in Java, all feedback welcome. ...
3
votes
2answers
89 views

Memory leak in Java's stack implementation

Recently I was asked to implement a stack specifically for storing 'int' type data and find memory leaks. Isn't the garbage collector responsible for releasing all the memory? What are the possible ...
6
votes
2answers
331 views

Array-Based Stack Data Structure in Java

So I've recently been writing simple data structures, even though they exist in the library it helps me understand them a lot better. Here is my code: ...
2
votes
1answer
44 views

Postfix evaluation using a stack in c

I have written a program to evaluate a postfix expression using a stack. I had my stack implementation using a linked list reviewed here, so I am only including the header file here. I have taken ...
8
votes
4answers
583 views

Array implementation of Java Stack

As an exercise, I wanted to make an array implementation of Stack, including most of the methods from the native Java Stack. ...
10
votes
3answers
389 views

Stack implementation with move semantics

I have implemented a basic stack just for fun. I've just started learning about move constructors and assignment and move semantics as a whole, so I would really appreciate some feedback as to whether ...
5
votes
2answers
247 views

Stack implemented using a single linked list

I am studying data structures and I have implemented a stack using a linked list. stack.h ...
4
votes
2answers
675 views

Simple FIFO and LIFO ferry simulator

I am trying to make a ferry simulator with one ferry that works like a stack and another like a queue. I have a working class for stacks and queues with pop/push; I am trying to figure out how to ...
-1
votes
2answers
103 views

Stack using two queues

I have implemented the Stack using two Queues q1 and q2 respectively as shown below in the code. I would like to get you reviews on whether it's an efficient way of implementing it or now. For Pop ...
3
votes
2answers
528 views

Implementing two stacks using single array in java

Please review the code ...
5
votes
1answer
44 views

ADT stack with a dynamic array (revision 1)

Here's the second draft of my ADT stack code which I posted here before after carrying out most of the improvements suggested there. I decided to expose a function called ...
4
votes
1answer
79 views

Stack implementation using arrays in Java

Could someone please review my code and let me know if there is any scope for optimization for better performance. ...
5
votes
4answers
170 views

ADT stack with a dynamic array

I'm starting to learn about data structures and coding in C. The stack is the simplest of all data structures so I'm trying to implement an ADT stack with dynamically allocated array in C. This ...
4
votes
2answers
134 views

Java Max-Stack implementation to return maximum value in the stack

I have written the below program to write a Java stack implementation. I have added a method which returns the maximum value in the stack, e.g, a pop. The implementation for this is based on the Max ...
8
votes
3answers
401 views

Simple implementation of a generic stack

I'm fairly new to C++ programming. To help I've been writing my own data structures for practice. I'd liked this to be judged as if it was written by a professional, and receive honest feedback. I ...
3
votes
1answer
65 views

Stack implemented with a linked list

I have made a basic stack class utilizing a linked list for data storage and \$O(1)\$ push and pop and just want some basic feedback on the class to see if there is anything basic I missed. It seems ...
5
votes
1answer
299 views

Palindrome using stack

I recently started learning Java, algorithms, and data structures. I am trying to check if a string is palindrome. I would like a review to see where and how I could improve. ...
5
votes
3answers
411 views

Stack Implementation in C++

This is my first template implementation. I'm trying to learn C++ and Algorithms. Any constructive criticism on code quality, readability is welcome. Everyone has their own style, but there are ...
7
votes
1answer
148 views

Stack using an array

I designed a simple drop-out stack a while back. Basically, I just want to get a few opinions on whether or not this is a good implementation and whether I am understanding the concept of a drop-out ...
10
votes
3answers
1k views

C++ Stack using template

I'm learning C++, so I wrote a stack with the help of templates. I'm wondering if there is anything I can improve or if I did something vastly wrong. Stack.h ...
5
votes
4answers
847 views

A data structure with push(int x), pop(), min() and max() in O(1)

I have written this Java code for a data structure which includes 3 stacks to supports four operations in \$O(1)\$: push(int x), ...
4
votes
3answers
39 views

Balanced expression checker

This program detects whether an expression is balanced or not. I would like to know how I can make this more efficient. ...
-3
votes
1answer
103 views

Implemented Stack using array

I'm going to job interviews soon. How I can improve my coding style and write better code? ...
3
votes
1answer
143 views

Priority stack in Java

I have this (simple) data structure that maintains multiple LIFO stacks. Each such stack is assigned a priority. The less is the value of a priority key, the higher the priority. Pushing operation ...
10
votes
1answer
517 views

Stack implementation using Swift

I would like to request some code review and feedback on a stack implementation using Swift. Disclaimer: I might have not used protocols, optional unwrapping and error and ...
5
votes
1answer
137 views

Stack implementation using linked list in C++

I'd like some feedback for the code I wrote. I haven't programmed in C++ for two years. ...
2
votes
3answers
62 views

ADT Stack with a doubly circular linked list

I have managed to implement an ADTStack with a circular doubly linked list. I would like to know whether there are things I could have done better or, I should ...
6
votes
2answers
251 views

Stack implementation with a linked list

Could anyone provide any constructive criticism? I'm trying to get a jump on data structures before classes start. One thing is that I should add a copy constructor and assignment operator. Changes ...
4
votes
2answers
50 views

ADT Stack with LinkedList

I am currently preparing for my exam and I am trying to implement some abstract data types with linked lists as preparation for the exam. I found an older exam from my prof. and he wants us to ...
8
votes
3answers
303 views

Generic stack in C

I tried to implement a generic stack in C using void pointers and tried to keep it as simple as possible by delegating all responsibility to the caller of the ...
6
votes
1answer
264 views

Lock-free bounded stack in C++11

Here is a classical attempt to implement a lock-free stack (based on this article). I rewrote it in C++11 and also tried to add memory orders which I would like to confirm to be correct. ...
4
votes
1answer
91 views

Lock-free bounded stack atomics

I was thinking about using very basic bounded (preallocated) stack to keep track of my threads IDs in correct LIFO order. I was wondering if my implementation is thread safe: ...
12
votes
3answers
1k views

Java and C++ stack implementations with dramatically different performance

I'm developing a small programming language for use in any project I have where I feel a small scripting language could be used well. I've written two emulators for the language, one in C++ and one in ...
3
votes
1answer
150 views

C-style generic stack implementation in C#

I saw a nice generic stack implemented in C, in Stanford's CS107 Programming Paradigms course, so I tried to rewrite it in C#: ...
6
votes
3answers
210 views

Stack with getMin method

This should implement a stack that has a \$O(1)\$ getMin method. I used an auxiliary stack. Please provide comments on my solution. ...
5
votes
1answer
2k views

Sort a stack in ascending order

Sort a stack in ascending order. You may only use one additional stack to hold items. Any comments on my solution? Worst case complexities: Memory complexity: O(n) Runtime complexity: O(n^2) Also, ...
2
votes
1answer
571 views

C++ program that recognizes a context-free language

This program (C++) was for a class project. A program that recognizes a given context-free language by implementing a pushdown-automaton (PDA). The PDA recognizes the following language: S → $T$ ...