infix-notation

Problems with stack in an infix to postfix converter

杀马特。学长 韩版系。学妹 提交于 2019-12-13 07:08:26
问题 Good day! I am implementing an infix to postfix converter using stacks. It works when the user input an infix expression with no parenthesis; but when a parenthesis is present, the console says: Exception in thread "main" StackEmptyException: Stack is empty. at ArrayStack.top(ArrayStack.java:85) at InfixToPostfix.convert(InfixToPostfix.java:54) at InfixToPostfix.main(InfixToPostfix.java:85) My problem is in implementing the rank (top of the stack). 回答1: Aha! You need "stack peek" when

Removing White Space: C#

爷,独闯天下 提交于 2019-12-13 04:34:48
问题 I am trying to remove white space that exists in a String input . My ultimate goal is to create an infix evaluator, but I am having issues with parsing the input expression. It seems to me that the easy solution to this is using a Regular Expression function, namely Regex.Replace(...) Here's what I have so far.. infixExp = Regex.Replace(infixExp, "\\s+", string.Empty); string[] substrings = Regex.Split(infixExp, "(\\()|(\\))|(-)|(\\+)|(\\*)|(/)"); Assuming the user inputs the infix expression

Common lisp: is there a less painful way to input math expressions?

房东的猫 提交于 2019-12-12 08:02:17
问题 I enjoy common lisp, but sometimes it is really painful to input simple math expressions like a(8b^2+1)+4bc(4b^2+1) (Sure I can convert this, but it is kind of slow, I write (+ () ()) first, and then in each bracket I put (* () ())...) I'm wondering if anyone here knows a better way to input this. I was thinking about writing a math macro, where (math “a(8b^2+1)+4bc(4b^2+1)”) expands to (+ (* a (1+ (* 8 b b))) (* 4 b c (1+ (* 4 b b)))) but parsing is a problem for variables whose names are

convert infix to Rpn (shunting yard)

て烟熏妆下的殇ゞ 提交于 2019-12-12 05:15:16
问题 here is my code to convert infix to ron using shunting yard . I know how the algorithm works well and I have no problem with that . but when I run this just nothing happen . when I debug it I get unknown error on stack initialization line #include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <stack> using namespace std ; void convert (char *) ; double eval(char *) ; int precedence(char); int main() { cout << "\n Enter an expression :\n" ; cout << " >> " ; char

Read, then store, a prefix expression

烈酒焚心 提交于 2019-12-12 02:49:43
问题 thanks for reading. I really need some help here. I'm faced with a problem that involves me using a recursive method to store a user-input fully marked prefix expression. In this particular instance, numbers are identified with the symbol "n", while symbols and such are just as they are. So, for example, this: % 18 + 14 / ( 12 – 11 ) – 1183 % 17 Would be input into the command prompt as this: % n18 / n14 - n12 n11 % n1183 n17 Now, here's what I have for the processing of a completely

Building parse tree from prefixed expression in c

坚强是说给别人听的谎言 提交于 2019-12-12 02:15:43
问题 I'm trying to create a binary tree like this: link The input will be entered by the user as prefix and read as a string, then put in a binary tree. This is what I have so far: struct node{ char val; struct node *left; struct node *right; }; typedef struct node root; typedef root *tree; In main: void main(){ int i; tree tr; char* s; s=input(); //input function tr=create_empty_tree(); for(i=0;s[i]!='\0';i++){ tr=add_root(s[i],ab); } convert_infix(tr); } and this is the part I've been struggling

Solving Infix Arithmatic in LISP

南楼画角 提交于 2019-12-11 20:00:55
问题 (defun solve (L) (cond ((null L) nil) (t(eval (list (car (cdr L)) (car L) (car (cdr (cdr L)))))))) The code I have is a simple evaluate program that works fine as long as the input is something like '(5 + 4). However I want to be able to solve other inputs such as '(5 +( 3 - 1)) and '(6 + 5) - (4 /2 ) . My problem obviously being how to handle the parentheses. I tried comparing the literal value of '( as in ((equal (car L) '( ) (solve(cdr L))) but that only throws all of my close parentheses

Standard ML, Infix identifier ERROR code

…衆ロ難τιáo~ 提交于 2019-12-11 07:22:42
问题 exception div; fun f(x,y) = let val before = 2.0 * x + 3.0 * y in (before + (1.0 / (if x > 0.0001 then x else raise div)) + 2.0 / y) handle div => before / 6.0 end This code yields some compile error. That is e.sml:4.8-4.14 Error: expression or pattern begins with infix identifier "before" e.sml:6.8-6.14 Error: expression or pattern begins with infix identifier "before" e.sml:6.57-6.60 Error: expression or pattern begins with infix identifier "div" e.sml:6.81-6.84 Error: expression or pattern

Prefix to Infix Conversion Algorithm with figure

人盡茶涼 提交于 2019-12-10 23:10:12
问题 After some google search I find it! Prefix to Infix This algorithm is a non-tail recursive method. The reversed input string is completely pushed into a stack. prefixToInfix(stack) 1) IF stack is not empty a. Temp -->pop the stack b. IF temp is a operator i. Write a opening parenthesis to output ii. prefixToInfix(stack) iii. Write temp to output iv. prefixToInfix(stack) v. Write a closing parenthesis to output c. ELSE IF temp is a space -->prefixToInfix(stack) d. ELSE i. Write temp to output

Convert from an infix expression to postfix (C++) using Stacks

旧巷老猫 提交于 2019-12-10 02:25:25
问题 My lecturer gave me an assignment to create a program to convert and infix expression to postfix using Stacks. I've made the stack classes and some functions to read the infix expression. But this one function, called convertToPostfix(char * const inFix, char * const postFix) which is responsible to convert the inFix expression in the array inFix to the post fix expression in the array postFix using stacks, is not doing what it suppose to do. Can you guys help me out and tell me what I'm