/infix2postfix

C program that reads an infix expression and converts it to a postfix one

Primary LanguageCMIT LicenseMIT

infix2postfix

This repository contains a simple algorithm written in C to convert an infix expression to a postfix expression.

Infix expressions

You're already familiiar with infix expressions. Infix expressions are expressions that contain operators (+-*/) between operands (numeric constants).

Examples of infix expression are:

2 * 6 + 1 / 4

5 * (7 - 5)

According to Silvio do Lago Pereira, in its book titled "Estrutura de Dados em C", there is a big problem with infix expressions: the existence of priorities, either due the operators (* and / have higher priority) or due parenthesis.

Postfix expressions

So, a long time ago, Jan Lukasiewicz created a different way of treating expressions and called it postfix notation or reverse Polish notation.

Basically, it consists of moving the operators to after the operands - not between anymore.

The previous infix expressions written in postfix notation are:

2 6 * 1 4 / +

(7 5 -) 5 *

The advantage of this notation for computational programs is that they can be easily interpreted using a Stack abstract data type.