Generation

generate functionWed, 03 May 2023

solicité expresiones que hacepte símbolos, letras y números y que está como resultado su notación en prefija, infija y posfija

Script const n = {'+': 2, '-': 2, '*': 3, '/': 3, '^': 4}; const p = {'+': 'l', '-': 'l', '*': 'l', '/': 'l', '^': 'r'}; function in2post(infix) { let stack = []; let postfix = ''; for(let i = 0; i < infix.length; i++) { if(infix[i].match(/[a-zA-Z]/)) { postfix += infix[i]; } else if(infix[i].match(/[()]/)) { if(infix[i] == ')') { while(stack[stack.length - 1] != '(') { postfix += stack.pop(); } stack.pop(); } else { stack.push(infix[i]); } } else { while(stack.length && n[stack[stack.length

Questions about programming?Chat with your personal AI assistant