stack

Exit program x86

旧街凉风 提交于 2020-07-10 09:38:20
问题 I am learning x86 assembly. I am trying to understand how "exiting program" works on x86. We have a code : push ebp mov ebp,esp //Some stuff here mov esp, ebp pop ebp ret When processor executes instruction "ret" : EIP will have value, which is popped from stack, in other words 0. so processor will go to 0 address and will try to execute instructions ... which doesn't contain program code/executable code. So, what is really going on with processor? Are there condition check, for example, if

Is there a better way to write a java code for detecting valid parentheses in a String?

旧时模样 提交于 2020-07-09 11:56:08
问题 I tried to solve a problem in leetcode and im not able to pass all the test cases. I tried to use stack. Whenever there is an open parenthesis, I push it into the stack and whenever there is a close parentheses, I check and pop if the correct open parenthesis is present on the top of the stack. I check if the stack is empty in the last Problem statement: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is

break; causing segment fault

北城余情 提交于 2020-06-29 06:28:08
问题 I was doing parenthesis checker using the stack. One of the if else statement containing a break; statement is causing segment fault. I tried removing the break program runs fine but prints the wrong answer as that break is needed to print correct output. What is the cause of such a segment fault? the break doesn't access any memory unit.right? Questions link #include <iostream> #include<stack> using namespace std; int main() { //code int n; char c,comp; cin>>n; while(n--) { stack<char>s;

why OS create the virtual memory for running process

这一生的挚爱 提交于 2020-06-29 03:48:14
问题 when a program started the OS will create a virtual memory , which divided into stack , heap , data , text to run a process on it.I know that each segment is used for specification purpose such as text saves the binary code of program, data saves static and global variable. My question is why the OS need to create the virtual memory and divide it into the segments ? How about if OS just use the physical memory and the process run directly on the physical memory. I think maybe the answer is

Java: LinkedList class as stack and queues

佐手、 提交于 2020-06-25 21:48:38
问题 I am new to LinkedList class, and facing difficulties as to how to use it in order to implement or instantiate stack and queues object. I am not looking for piece of self-implemented codes. I wanted to know how do we use this class as stack and queues and can use the already defined methods: pop,push,enqueue and dequeue or top (in case of stacks). 回答1: Queue A LinkedList is already a queue, since it implements the Queue interface (and check the Javadoc yourself). Hence it has the following

Java- Where does the variable name or Identifier gets stored, Stack or Heap?

南笙酒味 提交于 2020-06-22 12:46:07
问题 Where does the identifiers or variable name gets stored in java? I understand that objects get stored in heap and variable gets store in heap or stack depending on the type and scope of variable. Can we debug or write any program to confirm it? Thanks & Regards 回答1: Names of fields are stored as part of the class metadata, in formerly-PermGen now-Metaspace. Array elements don't have names, only numbers. (Cue Patrick McGoohan.) Names of method and constructor parameters and local variables and

JavaScript variable being ignored

删除回忆录丶 提交于 2020-06-17 09:41:29
问题 So I'm trying to write a Data Structures Visualizer with JS (so that I can host it online). It seems as though my JS ignoring my variables (and claiming some functions don't exist) and I can't figure out why. I'd appreciate the help. var stack = new Stack(); var defaultValueCounter = 0; function push() { var value = document.getElementById("add").value; if (value === "") { defaultValueCounter++; value = defaultValueCounter; } //console.log(stack + ", " + value) stack.push(value); addCol(value

JavaScript variable being ignored

牧云@^-^@ 提交于 2020-06-17 09:40:05
问题 So I'm trying to write a Data Structures Visualizer with JS (so that I can host it online). It seems as though my JS ignoring my variables (and claiming some functions don't exist) and I can't figure out why. I'd appreciate the help. var stack = new Stack(); var defaultValueCounter = 0; function push() { var value = document.getElementById("add").value; if (value === "") { defaultValueCounter++; value = defaultValueCounter; } //console.log(stack + ", " + value) stack.push(value); addCol(value

std::vector vs std::stack

家住魔仙堡 提交于 2020-06-10 07:26:49
问题 What is the difference between std::vector and std::stack ? Obviously vectors can delete items within the collection (albeit much slower than list) whereas the stack is built to be a LIFO-only collection. However, are stacks faster for end-item manipulation? Is it a linked list or dynamically re-allocated array? I can't find much information about stacks, but if I'm picturing them correctly (they are similar to an actual thread stack; push, pop, etc. - along with that top() method) then they

C# return struct reference from method

夙愿已清 提交于 2020-05-24 05:08:12
问题 In C++, returning a reference of an object allocated on the stack in a method, yields garbage values due to the fact, that the stack object is destroyed as soon the method leaves the scope. Given that in C# structs are allocated on the stack, would this yield garbage values as well? struct Test { //data } Test Foo() { Test t1 = new Test(); return t1; } 回答1: keyword struct in C# is allow to describe value type. When you return value type from method, it creates new copy of it. 回答2: I think you