What is Data Structure? Show the status of stack converting following infix expression to prefix

A+(B*C-(D/E^F)*G) [Note ^ is the power]

This answer is restricted. Please login to view the answer of this question.

Login Now

Data structure is a way of collecting and organizing data in such a way that we can perform operations on these data in an effective way. Data structure is about rendering data elements in terms of some relationship, for better organizing and storage.

Infix to Prefix:

First we will reverse the infix expression and find postfix. Then after we will reverse the result to get the prefix.

Reverse: (G*(F^E/D)-C*B)+A

Character Scanned Opstack Poststack
( (
G ( G
* (* G
( (*( G
^ (*(^ GF
E (*(^ GFE
/ (*(/ GFE^
D (*(/ GFE^D
) (* GFE^D/
(- GFE^D/*
C (- GFE^D/*C
* (-* GFE^D/*C
B (-* GFE^D/*CB
) GFE^D/*CB*-
+ + GFE^D/*CB*-
A + GFE^D/*CB*-A

Now, For Prefix we reverse the postfix:

Prefix: +A-*BC*/D^EFG

If you found any type of error on the answer then please mention on the comment or report an answer or submit your new answer.
Leave your Answer:

Click here to submit your answer.

  Loading . . .