In computer science, a linked list is a linear collection of elements, called nodes, each node have info field and next field pointing to the next node by means of a pointer. It is a data structure consisting of a group of nodes in sequence and connected with links. In simplest form of this data structure, each node is consist of data and a reference (in other words, a link) to the next node in the sequence. This structure allows for efficient insertion or removal of elements from any position in the sequence during iteration.
With a given Prefix Expression, we will see how to convert Prefix Expression into Infix Expression using stack. Algorithm to convert Prefix Expression to Infix Expression: In this algorithm, we will use stack to store operands during the conversion. The step are as follows: Read the prefix string While the end of prefix string scanned from right to left symb = the current character If symb is an operator poped_sym1 = pop the stack poped_sym2 = pop the stack concat the string STR = ( poped_sym1 )+ ( operator )+( poped_sym2 ) push the string STR into stack Else push the operand symb into stack End If End While infix_str = pop the stack Function to convert Prefix Expression to Infix Expression: void prefix_to_infix(char prefix[], char infix[]){ char op[2]; //operator string char poped1[MAX]; char poped2[MAX]; char temp[MAX]; int i = strlen(prefix); op[1] = '\0'; while(--i != -1){ if(prefix[i] == ' '){ continue; } if(isoper...
Comments
Post a Comment