stack

Can I reverse a queue without using stack?

大城市里の小女人 提交于 2020-02-02 12:54:11
问题 I have a queue with some numbers for example 5,6,7,8 is in queue, 5 is q->front and 8 is q->rear.. Can I reverse them in queue but without using stacks? 回答1: Of course! But it won't be as efficient. Using a stack: O(N) time. O(1) memory. Using an associative array: O(N) time. O(1) memory. Using a fixed-size array: O(N) time. O(N) memory. Using an extendable array: O(N) time. O(N) memory. Using a queue: O(N^2) time. O(1) memory. Using an associative array will use more time than using a stack,

Does it matter where the ret instruction is called in a procedure in x86 assembly

元气小坏坏 提交于 2020-01-30 10:53:37
问题 I am currently learning x86 assembly. Something is not clear to me still however when using the stack for function calls. I understand that the call instruction will involve pushing the return address on the stack and then load the program counter with the address of the function to call. The ret instruction will load this address back to the program counter. My confusion is, does it matter when the ret instruction is called within the procedure/function? Will it always find the correct

How to clear the Android Stack of activities?

痞子三分冷 提交于 2020-01-26 23:54:11
问题 I have an application with several Activities in Android and I want the user to be able to log-out by pressing a menu button. The problem I have is that A) Android doesn't let you terminate the application and B) even when I send the user to the LoginActivity again they can always press back and get right back to the previous activity they were in. I already tried to launch the Activity with the two following flags: Intent intent = new Intent(this, LoginActivity.class); intent.setFlags(Intent

Code works fine on my system but causes a stack smashing error when i submit it to the bot that is supposed to check it

拈花ヽ惹草 提交于 2020-01-26 04:11:07
问题 This program at this stage is supposed to get text from the user and separate it into paragraphs, sentences and words. The code works fine so far on my system(ubuntu 18.04) but when i submit it to the bot that is supposed to give input to it, a stack smashin error comes up. Is there a way to make my code read input without crashing? Edit: Here's a test input. I think the problem is that it reads it all at once.(also there are some other options apart from ap: that i haven't made yet): Test 3

which variable parts are stored to the stack in this code?

情到浓时终转凉″ 提交于 2020-01-24 22:55:30
问题 I have this following code and I don't really understand which variable parts in the test_function are stored onto the stack segment? In the book it says "The memory for these variables is in the stack segment", so I presume it is when the variables are actually initialized to a value. Right? void test_function(int a, int b, int c, int d) { int flag; //is it this char buffer[10];// and this //or flag = 31337; //this and buffer[0] = 'A'; //this. Or all of it? } int main() { test_function(1, 2,

Can a Forth-like language be implemented with just one stack?

那年仲夏 提交于 2020-01-24 13:04:25
问题 Forth has a stack and a return-stack. As far as I understand, the point of the return-stack is to store the previous values of the program counter. C programs put the previous value of program counter on the stack, and use no return stack. Does Forth only need a return-stack because it returns result(s) on the stack, and thus the previous value of the program counter could be buried? 回答1: The "Portable Assembly Language" should be close. It's a concept for a compiler for a language which is

In Java, why is it that a Stack is a concrete class whereas the Queue is an interface?

こ雲淡風輕ζ 提交于 2020-01-24 04:38:06
问题 Which one of Queue's subclasses is a 'plain ordinary' queue? 回答1: (1) java.util.Stack is a legacy class from Java 1.0. It predates the Collections framework by many years, and it's frankly an example of horrible design on many fronts. Nothing about it is the way things should be. The main problem is that Stack extends Vector , and as all inheritance in Java is public inheritance, all the methods of Vector are available on Stack as well. Therefore, you can inspect any position in a Stack, add

Infix to Postfix using Stacks Java

我的未来我决定 提交于 2020-01-22 16:28:11
问题 I am trying to write a program to convert an infix expression to a postfix expression. The algorithm that I am using is as follows : 1. Create a stack 2. For each character t in the expression - If t is an operand, append it to the output - Else if t is ')',then pop from the stack till '(' is encountered and append it to the output. do not append '(' to the output. - If t is an operator or '(' -- If t has higher precedence than the top of the stack, then push t on to the stack. -- If t has

Infix to Postfix using Stacks Java

浪尽此生 提交于 2020-01-22 16:28:08
问题 I am trying to write a program to convert an infix expression to a postfix expression. The algorithm that I am using is as follows : 1. Create a stack 2. For each character t in the expression - If t is an operand, append it to the output - Else if t is ')',then pop from the stack till '(' is encountered and append it to the output. do not append '(' to the output. - If t is an operator or '(' -- If t has higher precedence than the top of the stack, then push t on to the stack. -- If t has

Finishing all activities started before the activity

为君一笑 提交于 2020-01-22 12:32:07
问题 I want to finish all the activities which are running in the application means want to remove all the parent activities from stack. I want to implement logout functionality locally in my application so what I was thinking, I will finish all the activities started before and will start login activity again.. 回答1: I should let you know this is not a recommended behavior in android since you should let itself to manage life circles of activities. However if you really need to do this, you can