stack

Using Stacks In C++ for infix and postfix expressions

北城以北 提交于 2019-12-24 09:38:59
问题 I'm writing a program that takes user input and uses stacks to convert an infix expression into a postfix expression based on precedence, with operands always going before operators. For example, if a user inputs: (a+b*c) then the program should display: abc*+ so far, I have this: #include <iostream> #include <stack> #include <string> using namespace std; int main() { stack<char> s; char input; while (cin.get(input) && input != '\n') { if (isalnum(input)) cout << input << "\n"; else if (input

Why delete pointer to stack is error?

与世无争的帅哥 提交于 2019-12-24 09:27:48
问题 I have read topic Calling delete on variable allocated on the stack And i know when use operator delete in stack, see error. But i want to know more and deep information . Why error ? 回答1: Stack created objects are automatic whereas non-stack created objects (using the keyword new ) are dynamic and need to be reclaimed using the keyword delete . Objects on the stack are reclaimed by the system automatically using a different mechanism to objects allocated dynamically using keyword new . So

Do I understand the stack properly in this Y86 Assembly code?

筅森魡賤 提交于 2019-12-24 08:26:18
问题 I've created this simple and pointless assembly (Y86) code to see if I understand everything that's happening in the stack when the instructions call, pushl, popl and ret are used. Like I said, this code is pointless, it's just for testing/learning purposes. Although, all memory addresses were correctly (hopeful) calculated and are not random. The assembly code is the following: | .pos 0 0x00 | irmovl Stack, %esp 0x06 | rrmovl %esp, %ebp 0x08 | irmovl $5, %eax 0x0E | call func 0x13 | halt

using python 3 stacks to ensure symbols match in correct pairs and the types of symbols match as well

徘徊边缘 提交于 2019-12-24 07:52:20
问题 def spc(sym): stk1=myStack() stkall=myStack() for i in sym: if i not in stk1: stk1.push(i) else: stkall.push(i) for j in stk1: for k in stkall: if j==k: stk1.pop(j) stkall.pop(k) else: pass if len(stk1) == len(stkall): print("all symbols match") else: print(("these symbols, %s, have no matches")%(stkall)) Above code gives me this error "TypeError: argument of type 'myStack' is not iterable" But I fixed it by the answer from @SergeBallesta. After I edited code to look as you see now. Now im

Java Applet: Increase stack size

大憨熊 提交于 2019-12-24 07:06:03
问题 I was writing a small Java Applet in Eclipse to test a recursive algorithm. Since there are quite a lot recursive calls I needed to increase the stack size: -Xss10m This worked. Then I wanted to test the applet outside of Eclipse with appletviewer. So I wrote the needed html-file MyStuff.html: <html> <applet code="MyStuff.class" ARCHIVE=myjar.jar height=512 width=512> <PARAM name="java_arguments" value="-Xss10m"> </applet> </html> In order to start the applet I compile MyStuff.java: javac -cp

Sorting Arrays of objects by predefined map of values

橙三吉。 提交于 2019-12-24 06:26:39
问题 I have the following Arrays: $inputArray = Array( [0] => stdClass Object ( [id] => 8 ) [1] => stdClass Object ( [id] => 7 ) [2] => stdClass Object ( [id] => 5 ) ) $sortingArray = [5,8,1] I'm looking an efficient way to sort the input array by the id "map of values".. expected output should be $inputArray reordered so that 3rd item would be first, first item would be 2nd etc. thanks! 回答1: I've used a few things here, the main thing is that I use the sorting array as a target for an array

Sorting Arrays of objects by predefined map of values

一笑奈何 提交于 2019-12-24 06:26:03
问题 I have the following Arrays: $inputArray = Array( [0] => stdClass Object ( [id] => 8 ) [1] => stdClass Object ( [id] => 7 ) [2] => stdClass Object ( [id] => 5 ) ) $sortingArray = [5,8,1] I'm looking an efficient way to sort the input array by the id "map of values".. expected output should be $inputArray reordered so that 3rd item would be first, first item would be 2nd etc. thanks! 回答1: I've used a few things here, the main thing is that I use the sorting array as a target for an array

!address command shows a different value for the User mode stack initial commit size

♀尐吖头ヾ 提交于 2019-12-24 06:14:06
问题 I read in Windows Internals that when a thread is created, by default 1 MB of virtual memory is reserved for the user stack. Out of this 1 MB, only the first page (0x1000) will be committed. I can see this when i dump the image header using dumpbin.exe. Here is what dumpbin shows: However when i dump the address space of this exe in Windbg using !address command, I see a difference. Windbg shows me that the initial committed size is equal to 3 pages i.e 0x3000 Does anyone know why there is a

!address command shows a different value for the User mode stack initial commit size

旧街凉风 提交于 2019-12-24 06:12:51
问题 I read in Windows Internals that when a thread is created, by default 1 MB of virtual memory is reserved for the user stack. Out of this 1 MB, only the first page (0x1000) will be committed. I can see this when i dump the image header using dumpbin.exe. Here is what dumpbin shows: However when i dump the address space of this exe in Windbg using !address command, I see a difference. Windbg shows me that the initial committed size is equal to 3 pages i.e 0x3000 Does anyone know why there is a

Push method implementation using Stack and List ADT

社会主义新天地 提交于 2019-12-24 05:57:43
问题 How would I go about writing an implementation of push for the stack ADT using list ADT? Assuming i'm pushing to the top of stack, would I have to create a temp list and do something to add the previous head to the tail? private someList<E> stack; public void push(E element){ stack.add(element); } //another file public someList<E> add(E newHead){ return new someList<E>(newHead, this); } 回答1: What is important in the implementation of the stack ADT, is where you are going to add the new