Questions tagged [postfix-notation]

Postfix notation (also known as Reverse Polish Notation, RPN) is a mathematical notation wherein every operator follows all of its operands, in contrast to Polish notation, which puts the operator in the prefix position.

Postfix notation (also known as Reverse Polish Notation, RPN) is a mathematical notation wherein every operator follows all of its operands, in contrast to Polish notation, which puts the operator in the prefix position.

Both and postfix notation have the advantage over infix notation that operator precedence is completely defined by the expression, without parentheses being required, which further implies that both can be evaluated linearly by machine instructions without parsing.

572 questions
1
vote
1 answer

infix to postfix conversion using stack shows an infinite loop

below is the code of infix to postfix conversion using stack.The code executes an infinite loop printing stack underflow in one of the pop function ,i have tried commenting pop function call in right paranthesis loop but then there is no output, i…
1
vote
3 answers

If you have 4+3*2, is there an algorithm to calculate this in one pass?

So I implemented this before in JavaScript as a little practice and was sure I found a Wiki page for an algorithm that both converted a typical infix expression to post fix AND calculated the answer in the same pass In contrast, I can find this…
1
vote
0 answers

My question is about why should we use #include?

where is this header file is defined explain how this header file is used in this program and how it works.This code is working but I don't know how this header file is used in this program.Usually we define class for stack and its function inside…
1
vote
1 answer

Infix to Postfix Output program

I am a novice C++ programmer. I have written the following C++ code for infix to postfix expressing using an array-based stack, however, I get ^2 in string each time and also I can't figure out why my answer is not correct. I can't find the logical…
Ali M
  • 47
  • 3
1
vote
1 answer

infix to postfix converstion in C with multiple digits input

What I'm trying to obtain is a calculator that will take infix notation, ignore insignificant whitespace characters like " " or '@', then convert that infix notaion into postfix notation and do simple calculations like addition, subtraction etc. So…
1
vote
3 answers

Postfix Algorithm Evaluation in JS

this is what we start with: '7.7+7' The input of the function is an array of strings (original input converted to postfix): 7.7,7,+ then would get fed back into another function in order to display within my html page. this function is nested in…
1
vote
3 answers

How do I ignore spaces in a string input?

I am creating a program that evaluates a postfix expression contained in a single line of a text file. I'm having some trouble dealing with blank spaces in the scanned file. What I've done so far is scan the single line from the file into a buffer,…
1
vote
0 answers

Stack and pop() function in C

During an exercise, I've encountered an error: This is a piece of code of the evaluation function second_element = (*(long int*)upo_stack_top(stack)); upo_stack_pop(stack, 0); first_element = (*(long int*)upo_stack_top(stack)); upo_stack_pop(stack,…
F.G
  • 41
  • 1
  • 5
1
vote
2 answers

Converting infix to postfix using stack data structure with linked list

I am trying to create a program to convert an infix expression to a postfix expression using stack data structure in c++ using a structure Node. The related functions are there to push, pop values from the stack. The program compiles but after i…
1
vote
1 answer

Infix to postfix problem with unary operators

I use the following logic to implement an infix to postfix conversion, to evaluate it later. The loop on the infix conversion, and in each iteration, do the following: If space, ignore it. If operator, then keeps popping from the stack and add to…
1
vote
2 answers

Modify piece of code to allow floats and negative numbers as well as an arbitrary amount of spaces in between the characters in the inputted string

The following piece of code gets an infix string and will convert it to postfix and output that new expression as a string. However it does not support negative numbers or floats. The following code only allows for single digit values: Such as (0-9)…
user12522128
1
vote
1 answer

Time complexity of prefix to postfix conversion?

I think it should be quadratic i.e O(n^2). I am reading from this source prefix to postfix . I assume that appending two string takes linear time (O(sum of size of the two strings which we are appending)) and maximum number of times we need to…
user12007154
1
vote
1 answer

How to sum all the items in stack? Postfix calculator

I'm making a postfix calculator and I want to make a new feature to it. How can I sum all the items in a stack and then delete the items used for summing from the stack and then push the sum back to the stack? All this should happen by pressing…
MoskiMeruna
  • 17
  • 1
  • 5
1
vote
0 answers

Solved: Building a tree from postfix expression C++

I am currently working on calculating the value of a variable postfix expression, eg. a b + b c - *. For a specific state, a=1 b=2 and c=0, I can solve it with using a stack. Due to many possible given states (around 10^6) and calculating every…
Turtler
  • 11
  • 3
1
vote
2 answers

postfix evaluation , why is the push function not updating the top of stack variable?

when giving input "53+",it is pushing 5 and updates tos to 0 from '-1' but when the function is invoked for the second time, it pushes 3 but tos is still 0 , not 1. please help. #include using namespace std; int push(int tos, int x); int…