In the following code I give, everytime it will output ")".
Input :
((A+B)*((C-D)/(E^F)))
Expected output :
((A+B)*((C-D)/(E^F))) A+B*C-D/E^F
my output :
)
My code :
class Et: def __init__(self , value): self.value = value self.left = None self.right = None def isOperator(c): if (c == '+' or c == '-' or c == '*' or c == '/' or c == '^' ): return True else: return False def inorder(t): if t is not None: inorder(t.left) print (t.value) inorder(t.right) def constructTree(postfix): stack = [] for char in postfix : if not isOperator(char): t = Et(char) stack.append(t) else: t = Et(char) t1 = stack.pop() t2 = stack.pop() t.right = t1 t.left = t2 stack.append(t) t = stack.pop() return t postfix = "((A+B)*((C-D)/(E^F)))" r = constructTree(postfix) inorder(r)
Whatever code you have written does not take care of parenthesis like '(' or ')'. In order to get the correct output, you would need to take care of the parenthesis separately.
Only after you take care of them, you will get the desired output for the expression tree.
In the following code I give, everytime it will output ")". Input : ((A+B)*((C-D)/(E^F))) Expect...
Return a method as an expression tree Hi guys. I need to return a method as an expression tree, it's currently returning null. public static ExpressionTree getExpressionTree(String expression) throws Exception { char[] charArray = expression.toCharArray(); Node root = et.constructTree(charArray); System.out.println("infix expression is"); et.inorder(root); return et; } In the above method, et needs to have a value. -- Take a look at the complete class below. Kindly assist. ; public class ExpressionTree extends BinaryTree { private static final String DELIMITERS...
(Please help me with Coding in Python3) AVLTree complete the following implementation of the balanced (AVL) binary search tree. Note that you should not be implementing the map-based API described in the plain (unbalanced) BSTree notebook — i.e., nodes in the AVLTree will only contain a single value. class AVLTree: class Node: def __init__(self, val, left=None, right=None): self.val = val self.left = left self.right = right def rotate_right(self): n = self.left self.val, n.val = n.val, self.val self.left, n.left, self.right, n.right...
Previous code: class BinarySearchTree: def __init__(self, data): self.data = data self.left = None self.right = None def search(self, find_data): if self.data == find_data: return self elif find_data < self.data and self.left != None: return self.left.search(find_data) elif find_data > self.data and self.right != None: return self.right.search(find_data) else: return None def get_left(self): return self.left def get_right(self): return self.right def set_left(self, tree): self.left = tree def set_right(self, tree): self.right = tree def set_data(self, data): self.data = data def get_data(self): return self.data def traverse(root,order):...
python pls and noticed the output added "" One way to represent a binary tree is using the nested list format Consider the following binary tree: 24 72 78 8 51 25 This binary tree could be represented using a nested list as follows [55, [24, [8, None, None], [51, [25, None, None], None]], [72, None, [78, None, None ]]] The nested list format always uses a list of length three to represent a binary tree. The first item in...
Question 4 2 pts What is the output of the following code? def count(word): d = {} for char in word: if char in d: d[char] += 1 else: d[char] = 1 return d dictionary = count("Morgan Bears") print(dictionary["a"] + dictionary["r"])
Given a binary tree, it is useful to be able to display all of its data values. For this task, define a function called basic_print() which prints out all of the data values in a binary tree. The natural way to solve this problem is to use recursion. The diagram below illustrates a recursive solution to the problem, which consists of three simple steps: Step1: Print the root node Step 3: Print the right sub-tree 10 Step 2: Print the...
In the code below i am using a LS-3006 SERVO on the arduino uno and everytime i hit the pushbutton to input a time the servo comes on. Would anyone be able to tell me what a solution is to this problem? Thanks #include <Wire.h> #include <DS3231.h> #include <Servo.h> #include <LiquidCrystal.h> #include <Keypad.h> const byte ROWS = 4; // # of rows const byte COLS = 4; // # of columns // Define the Keymap char keys[ROWS][COLS] = { {'1','2','3','A'},...
1. What is the output? System.out.print(3 + 3 * 3); a. 18 b. 12 c. 9 d. 0 e. 10 2. What is output by the code below? System.out.print("\\dog\\cat"); a. dog b. dogcat c. \\dog\\cat d. \dog\cat e. catdog\\\\ 3. What is returned by the call getIt(9) ? public static int getIt(int num){ int ans = 0; if( num >=2 ) { if( num >= 7) ans += 2; else ans += 3; } ans += 4; return ans; }...
should be in C language What is the output of the following segment of C code: void CapsLetter (char* x, charl); int main() { char* text; text="This is some sample text."; CapsLetter(text, 'e'); printf("%s", text); return 0; سی void Caps Letter (char* x, char 1) { int i=0; while (x[i]!='\0') { if (x[i]==1) x[i]=1-32; } 1. This is som sample text. 2. THIS IS SOME SAMPLE TEXT. 3. This is some sample text. 4. this is some sample text. What...
24. What will be the output of the following code #include<stdio.h> int main() { char *p; p="%d\n"; p++; p++; printf(p-2, 100); return 0; } a. 100 b. 00 c. 10 d. compiler error e. none of the above 26. What will be the output of the following code #define TRIPPLE(x) (3*x) int x = 4; printf(“triple(%d) = %d \n”,x+1, TRIPPLE(x+1)); a. triple(5) = 12 b. triple(5) = 13 c. triple(4) = 14 d. triple(4) = 15 e. none of the...