stack

How can I remember which data structures are used by DFS and BFS?

I always mix up whether I use a stack or a queue for DFS or BFS. Can someone please provide some intuition about how to remember which algorithm uses which data structure? Thanks!! ...

Stack overflow - static memory vs. dynamic memory

If you write int m[1000000]; inside the main function of C/C++, it will get a runtime error for stack overflow. Instead if you write vector<int> m; and then push_back 1000000 elements there, it will run fine. I am very curious about why this is happening. They both are local memory, aren't they? Thanks in advance. ...

[Android] Activity problem

Hi guys, I have 3 activity in my application. My first activity (Main) has 2 button that starts other activities (One & Two). The One Activity starts a countdown timer on UI. When I click back button Android closes this activity and when I re-open activity, my timer is resetted. I try also overriding: public boolean onKeyDown(int k...

Where does the frame pointer point after set up?

Despite looking at textbooks trying to grasp this, I'm having trouble. 0x08048b29 <func+0>: push %ebp 0x08048b2a <func+1>: mov %esp,%ebp 0x08048b2c <func+3>: push %ebx ... 0x08048b30 <phase_2+7>: lea -0x28(%ebp),%eax In the lea instruction, I understand that %eax gets the value at 0x28 before %ebp, but wh...

Why won't my value increment? Memory stomping/stack glitch?

I've come across a rather charming bug that I'm trying to wrap my head around. I feel like I've seen this before, but this time I want to understand why this is happening. I have: int i; int debug = 0; for(i = 0; i < buf_end; i++) { do_some_buffer_work(); if(something_is_true()) { do_something_important(); pr...

Are these kinds of analysis for efficient use of stack frame memory slots possible ?

I know a compiler may detect life-time of different variables of a function and use the same stack frame slot for some different variables if it detects at beginning of life-time of each one of them life-time of previous variables has ended; but in case of local objects of classes in a function may it analyze life-time of members individ...

ASP.Net handler request stack

I've got a slightly odd requirement that I'm not sure how to properly articulate. I essentially want to prioritise the most recent requests to an ASP.Net handler. I'm not sure if this should be client-side or server-side. I'm leaning towards server side to ensure it's enforced on all clients. So, as requests come in, they're essentiall...

Why is my memory layout different?

The following code snippet: void (*foo)(); char X[1]; char Y[10]; could intruitively give me one possible stack layout of: | Y[10] | |---------| | X[1] | |---------| | foo | |---------| I examined this by generating the ASM file using: gcc -S -o stack stack.c Then I oberved that the order of pushing these variables is ...

Name three strategies for internal data storage when implementing a Stack ADT

This was a question my Data Structures teacher put on our recent test. I immediately thought of a List and an Array but I cannot for the life of me think of a third ADT that could be used as internal storage for a Stack. Any help? ...

Pushing a lua table

I have created a lua table in C, but i'm not sure how to push that table onto the top of a stack so I can pass it to a lua function. Does anyone know how to do this? This is my current code: lua_createtable(state, libraries.size(), 0); int table_index = lua_gettop(state); for (int i = 0; i < libraries.size(); i++) { lua_pushstring...

infix to postfix

Hi all, I've been trying to figure out this problem. I have an assignment to make a basic calculator. To do so i need the instructions in postfix. I have found some code online, which worked but used gets(). I tried replacing the gets... but the program no longer works. Here is the code, i was hoping someone could find the error (usi...

using ConcurrentStack

Hi, I need to use the stack data structure to save strings. But this stack will be accessed from multiple threads. So my question is, how do I use the ConcurrentStack to add data from multiple threads? ...

Returning value from a function

const char *Greet(const char *c) { string name; if(c) name = c; if (name.empty()) return "Hello, Unknown"; return name.c_str(); } int _tmain(int argc, _TCHAR* argv[]) { cout << Greet(0) << '\t' << Greet("Hello, World") << endl; return 0; } I see 2 bugs with the above code. Returning c_str from...

I want Flood Fill without stack and without recursion.

I wanted to know how to apply flood fill on array , my array is two dimensional , which contains times new roman font type letter boundry. The boundry line contains 1's and inside and outside all 0's. I want to fill all 1's instead 0 in only inside. But i need a logic which do not required more memory. So avoid recursion and stack or que...

Stack-based object instantiation in D

I'm learning D, and am confused by an error I'm getting. Consider the following: module helloworld; import std.stdio; import std.perf; ptrdiff_t main( string[] args ) { auto t = new PerformanceCounter; //From managed heap //PerformanceCounter t; //On the stack t.start(); writeln( "Hello, ", size_t....

Replacing recursion (with return values) with explicit stack

I was just wondering whether if it was possible to replace recursion with an explicit stack when you need the return value(s) and are comparing them to find the best solution (like dynamic programming)? So something like (it doesn't do anything, just an example): int resursiveFunction (int state) { if (known[state]) return cache[s...

How to prevent saving browser pages in activity stack history

User click one button on Activity#1 to start Activity#2. One button on Activity#2 start system default browser(Intent.ACTION_VIEW) to get Twitter authorized. After user allow, Twitter redirect user to Activity#2(Custom intent-filter+data) and it save the tokens. Now, if I press back key, the app back to browser, how to prevent this a...

Why is inlining considered faster than a function call?

Now, I know it's because there's not the overhead of calling a function, but is the overhead of calling a function really that heavy (and worth the bloat of having it inlined) ? From what I can remember, when a function is called, say f(x,y), x and y are pushed onto the stack, and the stack pointer jumps to an empty block, and begins ex...

List/tree/Stack - Algorithm

Hey guys, I need to do a project at the college, it needs to use list/tree/stack to perform any task. I was thinking on the Google's algorithm to recognize the phrase while the guy is typing. Does anyone has this algorithm? Or any other better idea that use list/tree/stack? Thanks ...

How to Detect Stack Unwinding in a Destructor

I have a simple C++ object that I create at the start of function F() to ensure two matched functions (OpDo, OpUndo) are called at the start and return of the F(), by using the object's constructor and destructor. However, I don't want the operation to be undone in case an exception was thrown within the body of F(). Is this possible to ...