stack

Use a stack to check .txt file for ('s, {'s, ['s, etc - Java

眉间皱痕 提交于 2019-12-11 16:45:42
问题 I am trying to write a method in java to search a text file that I imported for specific characters. The file is actually a java program that I designed and converted to a .txt file. When an opening brace/bracket is found, I am supposed to add (push) it to a stack and then when a corresponding closing brace/bracket is found I am supposed to remove (pop) it from the stack. The purpose is to see if I have the correct amount of ) , } , ] and > to correspond with the ( , { , [ and > . If they all

C++: How to search for quoatations using stacks

坚强是说给别人听的谎言 提交于 2019-12-11 16:12:28
问题 I have to create a program that reads in a text file and checks for matching parenthesis, brackets, [] , quote symbols, and block comment. If there is an imbalance it returns false, if it is balanced it returns true. I have done [] () {} and need help making it work for /* */ , " " , and ' ' where everything inside the single/double quotes and the block comments are ignored. I've tried many things but have been unsuccessful in getting them to work. 回答1: The program now needs to handle two

how do you multiply word-size inputs and get its word-size product in stack?

感情迁移 提交于 2019-12-11 15:48:04
问题 section .data msg db "Menu: " msgLen equ $ -msg msg2 db "[1]Factorial" msgLen2 equ $ -msg2mov dx, 0 msg3 db "[2]Power" msgLen3 equ $ -msg3 msg4 db "[3]Exit" msgLen4 equ $ -msg4 msg5 db "Enter number: " msgLen5 equ $ -msg5 msg6 db "Enter two numbers: " msgLen6 equ $ -msg6 line db "", 10 section .bss choice resb 1 num1 resw 1 quo1 resw 1 quo2 resw 1 quo3 resw 1 quo4 resw 1 quo5 resw 1 rem1 resw 1 rem2 resw 1 rem3 resw 1 rem4 resw 1 rem5 resw 1 section .text global _start _start: do_while: mov

returning alloca pointer

感情迁移 提交于 2019-12-11 15:17:39
问题 Does this code return an invalid reference to a variable allocated on the stack? Or what: void *f(size_t sz) { return alloca(sz); } Or is it a special case that is handled by the alloca implementation / compiler support like f(alloca(size), alloca(size)) would be? 回答1: alloca allocates space in the stack frame of f . You can't do anything useful with it once the function returns (it's not "reserved" anymore). The alloca() function allocates size bytes of space in the stack frame of the caller

Can I Limit the depth of a Generic Stack?

倖福魔咒の 提交于 2019-12-11 15:01:49
问题 Is there a built in way to limit the depth of a System.Collection.Generics.Stack? So that if you are at max capacity, pushing a new element would remove the bottom of the stack? I know I can do it by converting to an array and rebuilding the stack, but I figured there's probably a method on it already. EDIT: I wrote an extension method: public static void Trim<T> (this Stack<T> stack, int trimCount) { if (stack.Count <= trimCount) return; stack = new Stack<T> ( stack .ToArray() .Take

Recursion into stack-form. Preserving a search path towards ends of recursion

妖精的绣舞 提交于 2019-12-11 14:45:25
问题 A short form of question is: How do I convert a recursive search into a stack search? The trick is to be able to grab a branch that leads towards each of the recursion's endings. This Article's suggestion won't work as the path to the ending cannot be traced. (Ultimately if we could save each step into array via the reference to trace later on) I am using c#, and building a web of nodes. Each node contains an information about its neighbors. Also, each node contains 2 arrays. The 1st one is

How to increase height of particular subview of stack view at runtime?

心已入冬 提交于 2019-12-11 14:35:42
问题 I have added some arrangedSubViews to vertical UIStackView. and I want to increase height of one arranged subview inside on tap of some button. Tried adding layoutIfNeeded on subview and main view. Its Not working. I am increasing height of subview as below : addConstraints([self.heightAnchor.constraint(equalToConstant: 100)]) layoutIfNeeded() sizeToFit() layoutSubviews() 回答1: I think the problem is that you are trying to add a new constraint to the view but you didn't deactivate the existing

Linked list for stack, head->next keeps becoming null

两盒软妹~` 提交于 2019-12-11 13:47:07
问题 //Colin James P. Naranjo //CMSC123 CD-1L //This program demonstrates postfix evaluation through pop and push functions #include<stdio.h> #include<stdlib.h> #include<string.h> typedef struct node{ //Uses a combination of typedef and tagged structure for the singly linked list char value; struct node *next; }stack; char evaluate(char a, char b, char c){ int ans; if(c == '*'){ ans = (int)a * (int)b; } if(c == '+'){ ans = (int)a + (int)b; } if(c == '-'){ ans = (int)a - (int)b; } if(c == '/'){ ans

Understanding Postfix-expression Evaluation in Java code using a stack

一笑奈何 提交于 2019-12-11 13:36:09
问题 I was given a snippet of code to decipher, explain and offer any recommendations for improvement. I was told it works and we can't run the code to test it. I pretty much understand it but just need to run it by someone to make sure what I do understand about it is correct and please get any help with explaining what I don't understand.I have been doing a ton of research and still have some questions. The code is implementing used to read a postfix expression that only uses multiplication and

C++ std::stack Traversal

北战南征 提交于 2019-12-11 13:18:12
问题 I am using std::stack for an project and I need to travel on it for checking same values. I checked member functions but, I could not find an appropriate one for this task. The first idea that came up is using a copy stack but, the program might waste lots of extra space in this case, and not using an user-defined stack class is important at this level of the project (Yeah, I made a design mistake... ). So, any idea? Thank you! 回答1: Avoid std::stack , it's just a useless wrapper that dumbs