stack

Assign values of a stack to another stack

跟風遠走 提交于 2019-12-12 03:18:25
问题 I am working on this assignment. I need to create a temporary stack without initializing it. Then push the items of stack 1 into this temporary stack using a while loop. Then I need to use another (nested?) loop to walk through the temp stack and add the items from temp stack onto stack 2. Then I need to set stack 1 and 2 equal so stack 2 remains unchanged. 回答1: Your interfaces look a bit off. Let's start there and see if that gets you over your hump. stack.top() usually peeks at an item, but

Stack Using Linked List in C++

旧城冷巷雨未停 提交于 2019-12-12 03:16:04
问题 I'm trying to create a stack using linked lists in c++. But the display function i have written prints only the top of the stack. I can't really understand why this is happening. Any help or clarification is much appreciated. Thanks #include<iostream.h> #include<conio.h> class Node { protected: Node* next; int data; public: Node(int d){data=d;} friend class Stack; }; class Stack { public: Stack(){top->next='\0';length=0;} void push(int d) { Node *n=new Node(top->data); n->next='\0'; top->next

How does a system call restore the user level registers when it finishes executing?

核能气质少年 提交于 2019-12-12 03:04:08
问题 In Linux (kernel 3.14.4), a process usually has two stacks - the user level stack and the kernel stack. When a system call is invoked in the process, the OS will first push the current registers into the kernel stack, and then switch to the kernel stack to execute the system call. When the system call finishes, the values of the registers that were previously pushed into the kernel stack will be poped out and restored to the corresponding registers, so that the user level process can continue

Calculating Space Complexity of Stack Search

半腔热情 提交于 2019-12-12 02:44:53
问题 having a bit of issues understanding space complexity for a method. In the case of a stack and a search function, I understand that time complexity is O(n) since it depends on the amount of elements in the stack. What would the space complexity be in this case? Would it be O(1) since there are no variables or does the search consume extra memory based off the amount of elements and cause it to be O(n) ? Ex Function: return stack.search(item) != -1 Edit: Here is the built in function in

how to generate a stack trace from a core dump file in C, without invoking an external tool such as gdb

南笙酒味 提交于 2019-12-12 02:21:07
问题 I am looking for a simple way to pull the stack trace out of a Linux core dump file programmatically, without having to invoke gdb. Anybody has an idea? To avoid confusion: I am not looking for a way to get my own back trace from inside a process. I am looking for a way to get a backtrace out of a completely independent core dump file I have. 回答1: If you really can't invoke gdb, but want a backtrace like the ones it provides, you could just copy the bits of gdb's source that are needed for

Updating variable that lives in the data segment from the stack and its segment

ⅰ亾dé卋堺 提交于 2019-12-12 02:18:19
问题 I currently have three segments of memory, my main data segment, stack segment and the segment where my API lives. The following instructions are executed from the data segment, they push the address of cursorRow and welcomeMsg then do a far call to the function in my API segment. The cursorRow variable lives in the main data segment that is calling the API function. The call looks like this: push cursorRow push welcomeMsg call API_SEGMENT:API_printString How can I alter cursorRow, inside of

Stack returning Objects instead of Integers

落爺英雄遲暮 提交于 2019-12-12 02:09:46
问题 I'm trying to implement a program that involves an array of stacks. Each stack takes in Integer objects, but the problem is when I try to get an Integer object from the stack: import java.util.*; public class Blocks { public static void main(String[] args) { System.out.println(); Scanner input = new Scanner(System.in); Stack[] blocks = new Stack[input.nextInt()]; for (int i = 0; i < blocks.length; i++) {blocks[i] = new Stack<Integer>();} //initializing main array of stacks of blocks for (int

FASM- passing parameters to an external procedure

自古美人都是妖i 提交于 2019-12-12 01:59:02
问题 I am having trouble with passing parameters to procedures outside the main ASM file. Here is my code. It shows a main procedure, _main (in main.asm) which calls a sub-procedure _sub in another source file (sub.asm). The sub-procedure prints a string specified by the main procedure. main.asm: ;subprocedure test- main.asm org 100h include 'sub.asm' ;file of sub-procedure _main: ;main method mov dx, string ;move string to dx register push dx ;push dx onto the stack call _sub;calls sub-procedure

Converting a Postfix Notation to an ExpressionTree

二次信任 提交于 2019-12-12 01:48:21
问题 As it is said in the title I am trying to create a code which converts a postfix notation to an expression tree. Here you can check the constructor : public byte type; // 0 : operator, 1: operand (a number) public char operator; // One of '+', '-', '*', '/' public int operand; // A number ExpressionTreeNode(byte type){this.type = type; left=right=null;} and Here is my code : public static ExpressionTreeNode Postfix2ExpressionTree(String postfixExpr){ Stack s = new Stack<Object>();

python recursive iteration exceeding limit for tree implementation

时间秒杀一切 提交于 2019-12-12 01:43:40
问题 I'm implementing a tree dynamically in python. I have defined a class as below class nodeobject(): def __init__(self,presentnode=None,parent=None): self.currentNode = presentnode self.parentNode = parent self.childs = [] I have a function which gets possible childs for every node from a pool def findchildren(node, childs):` `# No need to write the whole function on how it gets childs Now I have a recursive function that starts with the head node (no parent) and moves down the chain