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

7
votes
2answers
190 views

Int stack implementation

#include <stdio.h> #include <stdlib.h> struct Stack { int value; int is_empty; struct Stack *next; }; int pop(struct Stack **stack) { if ((*stack)->is_empty == 1) { ...
3
votes
2answers
90 views

Dynamic stack in C - new version

Not long ago, I posted this dynamic stack for review. Now I wrote a new version, which is hopefully a better one. Please take a look and let me know how I could improve performance and increase code ...
5
votes
3answers
79 views

Dynamic stack implementation

I wrote this code for a dynamic stack and would like to know what would be better if done differently. It can increase memory by a percentage and/or fixed value when needed. It can also be set to not ...
-1
votes
2answers
999 views

Code review: infix to postfix converter [closed]

public static StringBuffer infixToPostfix(StringBuffer infix) throws InvalidCharacterException { StringBuffer postfix = new StringBuffer(""); Stack<String> myStack ...
1
vote
1answer
317 views

Postfix evaluation using a stack

I just wrote the code to evaluate a postfix expression and would like it if someone reviews it for me, it works perfectly fine but I'm having trouble adding the character "=" at the end. public ...
4
votes
1answer
160 views

Multi producer/consumers lockfree stack

Can you please take a look at the following x86-64 C++ code which should implement a multi consumer/produce lockfree stack? Do you think I have missed anything? namespace lockfree { // NOTE: this ...
3
votes
4answers
322 views

Reviewing my implementation of a stack using linked list

I have been studying data structures, and I'm new to this. Here is my code for the push and pop operations. I considered using a node=top, so that I can avoid O(n) operations for the push (i.e. ...
2
votes
2answers
108 views

Is it needed to “beautify” this Stack implementation?

I'm just learning OOP, and I have an assignment to create a Stack. I came up with the following. Is it "beauty" enough, or to "schooly". Where can I evolve? This is the class: class Stack { ...
2
votes
2answers
5k views

Stack implementation using linked list

This is a working stack implementation using a linked list. I'm just curious to know if this is a good way of doing it. Any suggestions are welcome. Can we keep track of the number of elements in ...
5
votes
1answer
143 views

How is my implementation of an immutable stack?

Below is my implementation of an immutable stack class. The reverse function is trying to return a stack with all elements reversed. Is my implementation good? Maybe the reverse function can be ...
0
votes
1answer
92 views

Linked stack and template class [closed]

I'm having problem making this linked stack working. The compiler is giving me errors and I've been checking for half an hour and still could not figure out what is wrong with my code. Would anyone ...
5
votes
2answers
249 views

Linked stack implementation in C++

Please feel free to be as harsh as possible. Implementation file: #include "Stack.h" #include <iostream> using namespace std; // Initializes an empty Stack. Stack::Stack() { this->head ...
1
vote
0answers
63 views

x86_64 assembly print integer stack allocation [closed]

I have made this simple assembly program that prints an integer in hexadecimal. It works, but I don't understand why it works with only a stack size of 15, when to print a 64 bit integer including 0x ...
4
votes
1answer
188 views

a working stack allocator

Here's an absolutely essential piece of C++ lore, a stack allocator, that will allow you to, say, allocate strings and vectors on the stack. There are 2 stack allocators I know of: ...
8
votes
2answers
207 views

How can this simple coroutine implementation be improved?

This is a quick and dirty implementation of coroutines that implements yield by saving and restoring the stack to and from the heap. Here's an earlier version, which does the most naive possible ...
2
votes
3answers
213 views

Review implementation of stack by using pointers in C

After I had my code for stack implementation by array reviewed I wrote stack implementation by using pointers. Here's my code. Any suggestions for improvement are welcome. I'll be adding updated ...
2
votes
2answers
389 views

Review implementation of stack by using array in C

This question has become long after many updates. Click here to go down. I have implemented stack using arrays in C. Please give me suggestions on how to improve it. The purpose of writing it is ...
4
votes
3answers
182 views

Template Stack class review

I am trying to mimic std::stack in my implementation (just the basic interface - no iterators / allocators). Since I was having trouble handling all the memory allocation/deallocation, I read this. ...
2
votes
2answers
331 views

Using pointers for string manipulation

I'm taking a sentence and determining whether or not it is a palindrome. I'm doing this while learning about stacks. Is there a way I can use pointers instead of char array 'sent' so that the number ...
5
votes
1answer
221 views

Immutable C++ stack - thoughts and performance

What are your thoughts on the fallowing immutable stack implementation? It is implemented having as a basis a C# immutable stack (where garbage collector assistance does not impose using a reference ...
3
votes
2answers
110 views

Another stack implementation (in C)

I just started learning C and the online book contained the exercise 'implement a stack'. So I did, but thought I'd put it here, because I still don't feel comfortable with pointers. So here it is: ...
1
vote
4answers
463 views

How could this postfix notation program be improved?

My postfix program allows the user two options one option for calculating a postfix equation: * Confirmations after each input (after an input, the user is ask for another number, operator, or final ...
6
votes
2answers
344 views

Valid Parentheses

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the correct order, "()" and "()[]{}" are ...
3
votes
4answers
124 views

How to Improve Stack Class C++ Implementation

This question is about improving my C++ coding skills. I was asked to implement a simple Static Integer Stack in C++ as an assignment. I've come up with the following code: class myStaticIntStack { ...
8
votes
2answers
337 views

Which is the most correct pattern for using Stack.Pop?

There at least 2 patterns of using Stack.Pop private Stack<T> availableResources; ... if (availableResources.Count > 0) { resource = availableResources.Pop(); ... } private ...
1
vote
2answers
370 views

Review C++ RPN Evaluator

So for Homework I had to write an RPN Evaluator and write the results to a text file. I've done all that - fine and dandy but it feels weird. Like the writing to my results text file. It doesn't feel ...
5
votes
3answers
1k views

A simple array-based Stack class in Java, what are my mistakes?

I have created a simple array-based Stack class with some methods like the actual Stack in Java. I am testing this for mistakes, but since I am learning Java and my tests may not be as comprehensive ...
0
votes
2answers
280 views

symmetric string checking [closed]

I wrote this routine in C to check the symmetry of a string using only a stack. (This is absolutely for educational purpose in our Theory Of Computation Class) Anyways, does this look right? For some ...
6
votes
3answers
243 views

implementation of a stack in C

Below is my implementation of a stack in C. Is it correct? And/or is there anything that I should fix to make it better in any way? stack.h #ifndef STACK_H #define STACK_H #define EMPTY_STACK -1 ...
2
votes
3answers
533 views

How to improve my stack implementation (uses array)?

Below is an implementation of a stack data structure using arrays. Please comment on the same. How can it be improved? Specific improvements I am looking for: Memory leaks C++ style Making code run ...
5
votes
2answers
521 views

Java and stacks: correct implementation?

I created this very simple stack concept's implementation. Could you tell me if it is correct and clean? Do you see any bad coding habits? public class MyStack { private static final int ...
3
votes
3answers
425 views

General purpose object array [closed]

I'm still new to Java and I'm trying to create a general purpose stack queue that uses an object array. I known that I've done things incorrectly, namely declaring the arrays and assigning the array ...
1
vote
4answers
4k views

Is this good code? Linked List Stack Implementation

I have used the following code for a stack implementation. The top keeps track of the topmost node of the stack. Now since top is a data member of the node function, each node created will have a top ...
4
votes
1answer
743 views

Tree-traversal without recursion

I wrote the following code for printing all the paths to the leaf nodes in a tree (NOT a binary tree ) without using recursion. I have used a stack and performed dfs on the tree. Whenever I reach a ...
5
votes
3answers
1k views

Simple stack implementation, how can I improve the code?

I am not experienced in C++, and wrote the below code for implementing a stack data structure using a linked list. Can you please point out any flaws, errors, stupid mistakes, general improvements ...
15
votes
0answers
453 views

How can I make my stack monad faster?

I made a stack monad that lets one manipulate and control values on a stack. I want to know if it's correct, (it seems correct), how to make it faster, and how I could detect stack overflows without ...
3
votes
1answer
233 views

Concurrent stack implementations in Ruby (relative performance of mutexes/CAS?)

This code is very simple, but it is intended as an experiment in the relative performance of mutexes/CAS on different platforms. The latest version can always be found at: ...