Questions tagged [stack]

A stack is a last in, first out (LIFO) abstract data type and data structure. One common use of stacks is to store subroutine arguments and return addresses.

0
votes
0answers
16 views

I am not able to use stack and Queue in my code i want to make calculator

I am not able to use stack and queue how use it for my code. plese help me to use it for my calculator i use script engine but it gives error while i call script enginemanger so i not understand which ...
0
votes
1answer
52 views

How to reach to the top element of a stack

I am trying to reach to the top element of the stack that was created for me. However, I keep getting errors ('top' is not accessible) and I am not allowed to change anything in the class. I created ...
1
vote
3answers
37 views

Declaring memory on stack overwrites previously declared memory

How can I allocate memory on the stack and have it point to different memory addresses so I can use it later? For example. this code: for (int i = 0; i < 5; i++) { int nums[5]; nums[0] = 1;...
-3
votes
0answers
25 views

Why every single test succeed but while all tests are running every failed?

Why when I run every test single every succeed but while are running all tests at a time some failed ? I have simple implementation of own stack. The class is called StaticStack and the class where ...
3
votes
1answer
35 views

Same logic is working for c++ but not in python for maximum in stack,is there something that i am missing in my code

I have written same logic in python and c++ to return maximum element in a stack in O(1) time using two stacks. but when I submitted it on hackerrank it is showing wrong answer for python but ...
1
vote
1answer
33 views

first node data in LinkedList not being recognized when called

I created a stack data structure from scratch using a linked list. It seems to push() properly because I can use the display method using first.data, and it displays the list. But when I use peek() I ...
0
votes
0answers
9 views

Size of a Raster Stack plot

I want to plot a RasterStack and i have a problem with the final size of the layers. Here is the code: plot(covs_mask[[1:14]],nc=2,nr=7) and this is the result but i want something like this, but ...
0
votes
1answer
49 views

Where is an array stored in memory in Javascript? [on hold]

We know objects are stored in the heap area. Suppose we are inside a function block where we declare: var a=[1,2] And var b=new Array(1,2) Will both the array objects be stored on the heap or ...
-1
votes
1answer
41 views

Finding k largest elements in an array in O(1) time

Is it possible to have O(1) time complexity in find the k largest or smallest numbers in an array, by making a stack class with an auxiliary data structure to track k largest/smallest in every push() ...
1
vote
1answer
70 views

Is there a way to do a circular stack?

Good afternoon ! I am trying to make some sort of circular stack. It should be like a normal LIFO stack, but without an apparent limit. Instead of hitting it's max capacity it should eliminate or ...
0
votes
1answer
44 views

Invalid conversion from 'char' to 'char* (*)()' [on hold]

I have written a code to convert infix to post fix but I have some error in the main here: while(!s.empty() && prcd(s.stacktop(),symb)) What does this mean and how can I fix it? #include &...
-2
votes
2answers
41 views

How to save int in a stack? (java beginner)

I am trying to save the value of an int that my server gets from the client to a stack but do not know where to begin or what to do. public class ser { public static int number, temp; public ...
0
votes
0answers
34 views

Stack List -> Circular List

I create an Stack List in C, with StackElement, Stack, Constructor, Destructor, etc. Now i want to connect the first list node with the header node. (circular list) How can I do this? My first Code ...
0
votes
1answer
51 views

Homework C programming stack and heap with string

This is a homework assignment that I could use some help with. I seem to have everything working, but I am having issues with the the name of the games. As you can see my names are not showing up ...
0
votes
1answer
32 views

Recieving error “cannot dereference out of range deque iterator” when utilizing top()

I'm creating a simple program to evaluate post fix expressions but it won't run after successfully compiling due to "Expression: cannot dereference out of range deque iterator" whenever it reaches the ...
0
votes
0answers
27 views

Understanding stack and red zone of a C program

Here is a simple C program: #include <stdio.h> int main(int argc, char* argv[] ){ int x = 10; int* ptr = &x; ptr++; printf("%x %d \n", ptr, *ptr); } Using a GNU ...
0
votes
1answer
9 views

Is the maximum call stack size in WebKit three times greater than that of V8? Why?

I see from this blog post the following function to compute the max call stack size: function computeMaxCallStackSize() { try { return 1 + computeMaxCallStackSize(); } catch (e) { ...
-1
votes
1answer
29 views

GCC's stack protection feature with optimization levels

I am doing some experiments with GCC's stack protection feature to understand it better. Basically I referred to this post on stackoverflow. The following is my code. test.c #include <stdio.h>...
3
votes
1answer
35 views

Stack frames visible in Visual Studio 2017 Call Stack are missing in System.Diagnostics.StackTrace when resuming C# async method

I have the following simple C# code snippet that uses asyc methods: class SUT { public async Task<int> GetValue() { await Task.Delay(1000); return 42; } } class ...
1
vote
2answers
68 views

Stack around the variable “name” was corrupted C++

I'm trying to use CStrings to do miscellaneous tasks in C++, such as remove all the vowels from the name provided. However, I can't seem to figure out why I'm getting this error: Stack around the ...
0
votes
0answers
20 views

How to remove certain element in a stack?

I'm having trouble removing a specific index in a stack, this code only remove the middle of the array. I want it to remove only specific index on (int i). public void RemoveAt(int i) { ...
0
votes
0answers
22 views

Infix to postfix conversion using stacks in C language

I am building a function to take the an infix expression from user and return its value. The input will be a postfix. Please can you find the error I made in the code because when I try to insert ...
-5
votes
2answers
60 views

Solving Palindromes using Stacks [closed]

bool isPal(string str) { Stack s1, s2; for(unsigned int i = 0; i < str.length(); i++) { s1.push(str[i]); } int s1_size = s1.size(); int s2_size = s2.size(); ...
0
votes
2answers
36 views

get the taken path until a line in python

Given a python function with nested if-else statements, how can we get the path we have taken to arrive to a line. def function(): if condition1: if condition2: sth else: ...
0
votes
1answer
9 views

SSRS : How to set SSRS stack chart X axis set range as <2500, 2500-4999

How to set SSRS stack chart X axis set range as <2500, 2500-4999 ....
0
votes
0answers
27 views

How the values are assigned in the implementation of stack?

I am a beginner in Java. So excuse me for any silly questions, I have the following code void push (int item) { if (tos == 9) System.out.println("stack is full"); else ...
-5
votes
0answers
22 views

(desperate)Write a program that will perform bracket matching and check a file named “program.txt” [closed]

i am desperate student i have a homework that requires me to: Write a program that will perform bracket matching and check a file named "program.txt" using c++ (pointers+stack) ,help would be much ...
3
votes
0answers
90 views

Is a lambda a proper object? [duplicate]

Exactly where is the machine code for a lambda stored, if the lambda takes an argument of auto type? Details follow. Lambdas are compiled at compile time, are they not? As far as I know, compilation ...
-1
votes
1answer
23 views

How to pop half a stack onto another stack

Hey I'm working on a program using two stacks (created using array) to determine if a string is a palindrome. I have declared two stacks. The plan is to read in the string, one by one, and push them ...
1
vote
0answers
22 views

Assembly weird stack usage [duplicate]

I have few questions about how stack is used in Assembly. As far as I know, the %rsp register is used as stack pointer. To allocate new memory on stack in Assembly code, you just subtract needed ...
-2
votes
3answers
49 views

Priority stack in C++

C++ standard library provides a priority queue with priority_queue. But does it also provide a priority stack ? I looked for priority_stack but did not find anything.
1
vote
1answer
73 views

Why we have a stack overflow in a recursive function in haskell?

where do i have an endless loop? f2 :: Int->Int->Int f2 n d | d==2 = 0 | n `mod` d ==0 && n`mod` d^3==0 = 1 + (f2 n d-1) | otherwise = 0 + (f2 n d-...
-1
votes
1answer
32 views

How to implement push and pop functions in a stack when there are constant variables(compilation error)

I am making a class for a stack for an assignment but some variables have to be const. Apparently that's causing an error because when I have to make the push and pop functions because of the const ...
2
votes
2answers
95 views

Stack implementation in C++ using a class causing segmentation fault

I have implemented some functions for a Stack in C++. I am unsure as to why I am getting a segmentation fault. Right now, I have 7 different files: node.h, node.cpp, LL.h, LL.cpp, Stack.h, Stack.cpp ...
0
votes
3answers
57 views

Comparing Two different data type pairs?

Im working on a problem to examine whether paranthesis are balanced or not in java. Each paranthesis has a type and a type is a random integer number. (0(1)1(2(0)0)2)0 ^this would be considered ...
0
votes
1answer
92 views

Implementing a Stack in C++ using a linked list

So I am trying to implement a Stack using a linked list and classes. Right now I have 6 different files: node.h, node.cpp, LL.h, LL.cpp, Stack.h, and Stack.cpp. I want to complete the Stack.h and ...
7
votes
2answers
286 views

Is there a particular reason that stacks and heaps aren't mentioned more often in C++ resources?

In books such as "C# in a Nutshell", what is allocated on the stack and heap is introduced quite quickly. However, C++ sources such as "Programming Principles and Practice Using C++", the standard, ...
1
vote
1answer
30 views

Maximum call stack exceeded RangeError

smallestInteger = (stack,numbers,k) => { if (stack.length == 0){ stack.push(numbers[k]); } if (numbers[k] <= stack[stack.length-1]){ stack.pop(); stack.push(...
-1
votes
4answers
33 views

Reversing an ArrayList of Integers with the aid of a stack

So I have managed to implement reversing an ArrayList (of Strings) with the aid of a stack, but I cannot figure out how to do it with integers. I get a stack empty error, any ideas? [Java] Here is ...
-1
votes
0answers
15 views

Has “Balanced Bracket” or “Valid parentheses” a brute force solution?

I'm starting with the brute force method to solve problems. But sometimes I encounter problems that seem don't be approachable with brute force, is this problem one of them, isn't it?
0
votes
0answers
21 views

Multiple Parenthesis using Stack

A sequence of parenthesis is said to be ‘balanced’ if each opening symbol has a corresponding closing symbol and the pairs of parentheses are properly nested. For example, (()(())) is balanced and (())...
1
vote
2answers
67 views

The Java stack and recursion

My question is about the design of the Java stack. Was it designed with recursion in mind, or did recursion become a thing due to the structure of the stack?
0
votes
2answers
63 views

depth first search with 2D Array

I have an array like that : 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 1 1 1 0 0 1 0 1 0 0 1 1 0 1 0 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 And I want to group elements which ...
-2
votes
0answers
39 views

Segmentation fault tying to pop a pointer to a struct onto an array of pointers to a struct

I keep getting a segmentation fault trying to pop a customer (a struct in a header file that is later made into a pointer) onto an array of registers (another struct made up of a customer and employee)...
2
votes
1answer
52 views

Newline byte 0Ah being ignored by x86_64 system call print program

I followed a simple tutorial in the creation of a NASM x86_64 program which uses the defined functions to print variables with a new line added to the end. sprintLF calls sprint which in turn prints ...
-2
votes
0answers
15 views

Adding an item to a stack at random in Python 3

This is the code I have for the issue. I need to use a random number to add one item to a stack 60% of the time and remove something from the stack 40% of the time and I need to keep track of ...
2
votes
1answer
120 views

Testing for too many operands on C++ postfix to infix stack

I'm currently trying to test for if there are too many operands but cannot figure out the condition for when a postfix expression has too many operands. Could someone give me any pointers on what to ...
2
votes
2answers
59 views

NASM x86_64 printf 7th argument

I have a simple dprintf program written in NASM which prints a long format with more than 6 arguments. I am passing the arguments as the calling convention requires (RDI, RSI, RDX, RCX, R8, R9). As ...
-2
votes
2answers
50 views

Object oriented programming - C++ exercise

#include <iostream> #include <string> #include <cstdlib> #define MAX_SIZE 100 int pos=-1; using namespace std; class StackElement { private: int data; string name; ...
2
votes
0answers
40 views

Fill an empty stack with numbers from other k stacks such that sum of squared distance between adjacent numbers in new stack is minimized

There are k stacks already filled with numbers with range[0,5]. I need to fill an empty stack by popping the numbers from other k stacks and pushing them to this stack. I need to do it in such a way ...

http://mssss.yulina-kosm.ru