How to sort an array in descending order using sort() in c++?

The C++ STL function sort() by default sorts the array in ascending order. If we want to sort array in descending order using sort(), we need to use a Comparator Function. Syntax Sort Array in Descending Order Using sort() We can use the inbuilt greater<type>() function to arrange array in descending order. greater<type>() compares the …

How to sort an array in descending order using sort() in c++? Read More »

Queue

Queue is a linear data structure. It follows First In First Out (FIFO). In other words, the item which is inserted first is accessed/deleted first. For example, when you go to cashier in a mall, then the person first in line is served first. This is a queue. Basic Operations:- enqueue/push: Insert item in the …

Queue Read More »

Postfix to Infix

We can convert any postfix expression to infix expression using stack in one pass. Example Input: abc^d/e*+ Output: (a+(((b^c)/d)*e)) Postfix to Infix Algorithm Steps Initialize an empty stack. Scan postfix expression from left to right. If the scanned character is an operand, push it to the stack. If the scanned character is an operator, Pop …

Postfix to Infix Read More »

Infix to Postfix

We will study how we can convert infix expression to postfix expression using stack. Infix Expression Infix Expression is in the form of Operand Operator Operand.For example, 4 + 5. Postfix Expression ( or Reverse Polish Notation ) Postfix Expression is in form Operand Operand Operator.For example, 4 5 +. Before moving ahead we must …

Infix to Postfix Read More »