stack

Generic Stack Array

两盒软妹~` 提交于 2020-01-02 06:26:21
问题 I have to implement a generic stack, but when I try to build the project I have an error that I can't figure out. Here's the code: Stack.java -> interface package stack; public interface Stack <T> { public boolean isEmpty(); public boolean isFull(); public void push(T x) throws StackFullException; public boolean offer(T x); public T pop() throws StackEmptyException; public T poll(); public T peek() throws StackEmptyException; public T element(); } StackArray.java -> the implementation of the

Design a stack that can also dequeue in O(1) amortized time?

[亡魂溺海] 提交于 2020-01-02 05:22:31
问题 I have an abstract data type that can be viewed as a list stored left to right, with the following possible operations: Push: add a new item to the left end of the list Pop: remove the item on the left end of the list Pull: remove the item on the right end of the list Implement this using three stacks and constant additional memory, so that the amortized time for any push, pop, or pull operation is constant. The stacks have basic operations, isEmpty, Push, and Pop. Amortized time means "If I

Why does allocating a large element on the stack not fail in this specific case?

橙三吉。 提交于 2020-01-02 04:58:05
问题 When allocating a int as well as a large array on the stack in C, the program executes without error. If I however, initialize the variable on the stack beforehand, it crashes with a segfault (probably because the stack size was exceeded by the large array). If initializing the variable after declaring the array this would make sense to me. What causes this behavior, memory wise? I was under the impression, that by simply declaring a variable on the stack, the needed space would be allocated,

How can we poll the stack status - unused (available) memory

白昼怎懂夜的黑 提交于 2020-01-02 04:45:20
问题 How can we get this information? I guess it is OS dependent, and I'm running Windows so my question refers to the windows API. Is there any function that can do that for us - get the remaining stack memory for the calling thread? Alternatively, if we could find out the following details, we will be able to calculate that on our own: Get the thread stack base address . There must be some function that takes a thread identifier as a parameter, and returns some information about it (Such as...

memory allocation for objects

空扰寡人 提交于 2020-01-02 04:41:28
问题 When we instantiate a variable in c++ like int x within a function(i.e. x is a local variable), it is allocated on top of stack of the process. But if we do int *x= new int , the space is provided in heap. So, my questions are: What about objects of different classes (classes provided by c++ or user defined)? Where are their objects instantiated? For example: Let Employee is a class and we declare Employee emp; . Where is emp given space-> on stack or in heap? If the declaration int a[4] is

What maximum size of static arrays are allowed in C?

淺唱寂寞╮ 提交于 2020-01-02 04:11:10
问题 In my algorithm I know work with static arrays, no dynamic ones. But I sometimes reach the limit of the stack. Am I right, that static arrays are stored to the stack? Which parameters affect my maximum stack size for one C programm? Are there many system parameters which affect the maximal array size? Does the maximunm no. of elements depend of the array type? Does it depend on the total system RAM? Or does every C programm have a static maximum stack size? 回答1: Most of your questions have

android insert into activity stack

家住魔仙堡 提交于 2020-01-02 03:30:11
问题 Here is the question: Let's say the activity stack consist of A->B->C. If user followed the order eg: Start A -> B -> C, pressing back button will cause C->B->A. However, if user entered directly into activity C (eg: via notification), pressing back button will cause the app to close, instead of going into B->A. How do I insert the into the activity stack to become A->B->C, so that when user pressed back at C, it will always back to B. Thanks 回答1: just overide the onBackPressed() method and

How do I increase the stack size in python

久未见 提交于 2020-01-02 02:06:32
问题 I have a python program that uses a custom-built DLL. This DLL crashes due to a stack overflow. This overflow is not due to a recursive function gone bad, but to large allocations on the stack using alloca(). I want to increase stack size to get rid of this error. Is there any way to do this? 回答1: AFAIK a program can only change the stack size of new threads or processes (Windows' CreateThread function, for example). As Python (and the Win32 API for Python) does not expose such functionality,

Is there a stack space for every thread?

坚强是说给别人听的谎言 提交于 2020-01-02 01:13:10
问题 If I understand correctly the stack is for local primities and references to the objects in the heap. So what happens if you have more than one threads? Do they share the same stack space at the same time (but different areas) or does the JRE switch contexts and load-deload the stack content when switching between threads? Or does the JRE allocate separate stacks for each threads? 回答1: Or does the JRE allocate separate stacks for each threads? Conceptually yes. (See this JVM spec link, for

Android onSearchRequested() callback to the calling activity

我是研究僧i 提交于 2020-01-01 18:19:09
问题 I have a MapActivity that will display the Android Search box when a search button is pressed. The SearchManager manages the dialog, and passes the user's query to a searchable activity, which searches an SQLite DB and displays the results using a custom adapter. This works fine - and I'm getting the correct results from the DB displayed. However, what I want to do is display the result in the MapActivity on a map when the user clicks on a search result. Currently, this means starting a new