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
2 votes
1 answer
39 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 ...
user avatar
4 votes
2 answers
436 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 ...
user avatar
2 votes
2 answers
51 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 ...
user avatar
2 votes
0 answers
30 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 ...
user avatar
5 votes
2 answers
161 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 <...
user avatar
7 votes
1 answer
285 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 ...
user avatar
0 votes
0 answers
85 views

Stack test with JUNIT testing

I need help to understand how i should write the test in Stack test class. Down under I have included the stack interface, Linkedlist class that implements the stack test, the linkedList test that ...
user avatar
3 votes
1 answer
113 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. ...
user avatar
  • 131
1 vote
0 answers
40 views

My code generates a path through a grid - How can I simplfy it in terms of list, dictionary's, stacks and queues?

This code works but is cluttered and I think could be improved in terms of how it is implemented. Basically my code works - what it does is from the start location, it chooses a random direction and ...
user avatar
1 vote
1 answer
39 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? ...
user avatar
  • 11
-1 votes
2 answers
92 views

Optimization suggestions for my Stack [closed]

stack.hpp ...
user avatar
2 votes
1 answer
121 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 ...
user avatar
3 votes
4 answers
152 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 ...
user avatar
  • 31
3 votes
2 answers
75 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: ...
user avatar
3 votes
2 answers
166 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. ...
user avatar
  • 39
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 ...
user avatar
2 votes
3 answers
103 views

C++ evaluating an arithmetic expression in RPN format using ADT stack

Write a program that uses an ADT Stack to evaluate arithmetic expressions in RPN format. The contents of the stack should be displayed on the screen during evaluation. The allowed arithmetic operators ...
user avatar
  • 21
6 votes
1 answer
512 views

Calculator in C - Parsing arithmetic expression using the shunting-yard algorithm

This is a simple arithmetic calculator, which parses mathematical expressions specified in infix notation using the shunting-yard algorithm. This is one of my personal projects and I would love to ...
user avatar
1 vote
1 answer
81 views

Stack of integers in C

I'm learning C, and currently I follows C99 standard. Here is my implementation of integer-stack, which is just a stack you can do: push, pop, and print the content ...
user avatar
3 votes
1 answer
95 views

Python Console App | Is there a better way to go back a page?

I have a system for going back to a previously-visited page in a Python console application; it works well enough, but I feel that there could be a prettier way of doing it. Does anyone have any ...
user avatar
1 vote
0 answers
295 views

Add missing left parentheses in Java [closed]

I wanted to write a program that takes from standard input an expression without left parentheses and prints the equivalent infix expression with the parentheses inserted. For example, given the input ...
user avatar
  • 11
3 votes
2 answers
125 views

A toy example of the concurrent stack via atomic variables and CAS pattern

I've written a toy example of the concurrent stack which has only three functions push(), peek(), and ...
user avatar
0 votes
1 answer
109 views

Generic stack implementation in C

I haven't separated the stack code into its own header and source yet, this is just a proof of concept for now. Haven't chosen better function names yet because I ultimately want to integrate this ...
user avatar
  • 215
1 vote
0 answers
82 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 ...
user avatar
  • 196
2 votes
1 answer
99 views

C++ implementation of a Stack with dynamic C-style array

I implemented a Stack in C++ using a dynamic C-style array. I tried sticking to the most important functions a Stack has to have to be usable. This is meant to only be for integers. I appreciate any ...
user avatar
  • 390
6 votes
2 answers
151 views

Error Code Stack Trace and Propagation Library in C

I've been programming in Go and I enjoy how easy it is to create descriptive errors and propagate them up the call stack. I wanted that sort of ease and consistency in C so I created a small error ...
user avatar
  • 163
4 votes
1 answer
98 views

Assemble network packet on stack for iovec

The recurring problem to assemble a network packet out of payload, sequence number, header, and other misc. information is mostly solved either on the heap (e.g. appending to a ...
user avatar
2 votes
2 answers
2k views

Dynamic Array Based Stack in C

I wrote a dynamic stack in C that uses an array as a structure. I tried to maintain O(1) for push and pop and believe I have done so. I want to know what can be written in a cleaner way and if there ...
user avatar
  • 123
3 votes
2 answers
653 views

Convert infix regular expression notation to postfix

This is a small part of a larger program for implementing a limited syntax regular expression constructor using Ken Thompson's construction algorithm. Converting to postfix before the regular ...
user avatar
7 votes
1 answer
5k 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. ...
user avatar
2 votes
1 answer
387 views

Kotlin Stack using an ArrayList to compare and remove elements

Is this a performant strategy to implement a stack in Kotlin to compare and delete values? Expect Create a stack in order to compare an array of asteroids (ASTs) and handle collisions (deletions), ...
user avatar
10 votes
2 answers
599 views

An attempt at a toy Vm

I usually use c++ so it may not be best practice for c. This is a stack based toy vm and as a result it is very primitive, and it has no bitwise instructions 64k might be a bit overkill for a toy vm. ...
user avatar
  • 109
1 vote
1 answer
92 views

Stack Implementation Using Linked Lists

I have tried Implementing Stacks Using Linked Lists, and would like some tips and tricks regarding optimizations or ways to simplify/compact processes. It has 3 functions, Push, Pop, and Peek (For ...
user avatar
  • 1,180
1 vote
0 answers
26 views

regex on a log file utilizing stacks and queue's in Java

This would be for a MUD client, which has elements of a sort of telnet bot. Here, there's ...
user avatar
  • 389
-3 votes
1 answer
47 views

What's wrong with this stack implementation? [closed]

My CS teacher sent me the following code for implementing the stack. I've been programming for a few years in higher-level languages, but have rather weak experience with C++. I mean, this code just ...
user avatar
9 votes
4 answers
3k views

Simple Stack implementation in C++

I've recently started teaching myself basic C++ and decided to implement a simple stack with pointers. ...
user avatar
1 vote
1 answer
567 views

Concurrent Queue with enqueue and dequeue using Stack as underlying data structure

This is a mix of data structure and multi threading concept based question. (This is only for understanding and learning purpose) The language for the solution : Java A Queue with FIFO behavior needs ...
user avatar
2 votes
2 answers
68 views

Queue By Using Stack

I have implemented a queue by using a stack data structure. How could I improve it? ...
user avatar
7 votes
3 answers
256 views

Dynamic stack implementation in C

I've been studying C for a while, as a programmer coming from a C++ background, I'm used to the standard library, STL, etc., and I quickly realized that I need some kind of a containers library/data ...
user avatar
1 vote
4 answers
1k 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. ...
user avatar
  • 620
3 votes
2 answers
2k views

Basic 'char' Stack implementation in C

...
user avatar
  • 1,323
3 votes
3 answers
540 views

Stack implementation using linked-list

typedef struct Stack { char v; int x; int y; struct Stack* next; } Stack; Above is my stack struct. ...
user avatar
  • 39
4 votes
1 answer
66 views

C pointer based growable stack rev2

Following on from my previous question: C pointer based growable stack I have made some improvements (hopefully!) based on the very helpful comments and suggestions. I have checked that the stack can ...
user avatar
  • 133
7 votes
3 answers
1k views

C pointer based growable stack

This is my first attempt at writing a C program, it a generic stack that can grow accordingly. It appears to work correctly, however I am worried that is just a fluke and I could be doing something ...
user avatar
  • 133
4 votes
1 answer
495 views

Codility Fish (queue) programming challenge

Today I have attempted a Codility exercise "Fish" (https://app.codility.com/programmers/lessons/7-stacks_and_queues/fish/), and I have to say I found it to be: 1) Not necessarily "easy" as implied by ...
user avatar
  • 143
2 votes
2 answers
108 views

Designing a stack such that getMin() is both constant time and constant space

I'm attempting the SpecialStack problem on GeeksforGeeks. Design a data-structure SpecialStack (using the STL of stack) that supports all the stack operations like push(), pop(), isEmpty(), ...
user avatar
1 vote
1 answer
173 views

Syntax Checker C++ Data Structure - Stack

Syntax Checker is a very common question of c++ programming using the data structure stack. However, this is the advanced level base on this question I found in a reference book. Here is the question: ...
user avatar
17 votes
7 answers
3k views

Stack data structure in Python 3

I have implemented a stack in Python 3, and it works well. If anything needs to be improved, I would appreciate the criticism. ...
user avatar
6 votes
1 answer
3k views

Doubly Linked List using Stack in c++

Just started learning/relearning data structures for the semester exams. Most of the examples found online are too cluttered or bloated. For myself, I implemented it from theory I learned. It works....
user avatar
1 vote
1 answer
2k views

Codility's stonewall 100% solution - different paths such as if,else if,etc, do the same thing

Here is the task description for the codility's stonewall problem. I would like to get a feedback on my code, and I specify at the bottom what the title states. (I had to make the figure by hand, ...
user avatar
  • 869

1
2 3 4 5
9