{"componentChunkName":"component---src-templates-blog-post-jsx","path":"/blogs/infixToPrefix","result":{"data":{"blog":{"frontmatter":{"title":"INFIX TO PREFIX CONVERSION","thumbnail":"blog31","date":"December 27, 2020","dsaCppCodeFile":"https://drive.google.com/file/d/1aM3T9SU50PO4HvbUTfujSXqmLKGOkkFP/view?usp=sharing"},"excerpt":"<div class=\"my-2 p-2\">\n              <p>\n                Lets see the precedence of the operators that will be used to\n                convert the given infix to prefix expression and understand the\n                logic for conversion.\n              </p>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Precedence</h4>\n              <div class=\"table-responsive\">\n                <table class=\"table table-striped\">\n                  <caption class=\"text-center\">\n                    Precedence\n                  </caption>\n                  <thead class=\"thead-dark\">\n                    <tr>\n                      <th>Operator</th>\n                      <th>Stack precedence</th>\n                      <th>Input precedence</th>\n                    </tr>\n                  </thead>\n                  <tbody>\n                    <tr>\n                      <th>+ -</th>\n                      <th>2</th>\n                      <th>1</th>\n                    </tr>\n                    <tr>\n                      <th>/ *</th>\n                      <th>4</th>\n                      <th>3</th>\n                    </tr>\n                    <tr>\n                      <th>^</th>\n                      <th>6</th>\n                      <th>7</th>\n                    </tr>\n                    <tr>\n                      <th>(</th>\n                      <th>0</th>\n                      <th>9</th>\n                    </tr>\n                    <tr>\n                      <th>)</th>\n                      <th>-</th>\n                      <th>0</th>\n                    </tr>\n                  </tbody>\n                </table>\n              </div>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Logic for conversion</h4>\n              <p class=\"text-muted\">\n                Do refer the code available the end of this section to\n                understand the following theory.\n              </p>\n              <ol class=\"pl-4\">\n                <li>\n                  Create two stacks using arrays of type character, one for\n                  operand stack and another one for operator stack.\n                </li>\n                <li>\n                  There occurs a situation to perform the following operation:\n                  <ol class=\"pl-4\">\n                    <li>\n                      Pop the top of operand stack and save it as operand2.\n                    </li>\n                    <li>\n                      Once again pop the top of operand stack and save it as\n                      operand1.\n                    </li>\n                    <li>\n                      Copy the incoming operator into a temporary expression.\n                    </li>\n                    <li>\n                      Concat the operand1 and then operand2 to this temporary\n                      expression.\n                    </li>\n                    <li>\n                      Finally push this temporary expression to the operand\n                      stack.\n                    </li>\n                  </ol>\n                </li>\n                <li>Scan the infix expression from left to right.</li>\n                <li>\n                  If the character read is an operand then push it to the\n                  operand stack.\n                </li>\n                <li>\n                  Else loop until the operator stack is not empty and stack\n                  precedence of top(of operator stack) is more than the input\n                  precedence.\n                  <ol class=\"pl-4\">\n                    <li>\n                      If the input character is ')' then perform step 2\n                      operation until the top of stack is not '('.\n                    </li>\n                    <li>\n                      Pop the top of operator stack because it will obviously be\n                      '(' and break the loop(step 5).\n                    </li>\n                    <li>\n                      Else if the input character is not ')' then perform step 2\n                      operation.\n                    </li>\n                  </ol>\n                </li>\n                <li>\n                  If the step 5 condition fails and input character is not ')'\n                  then push the operator into the operator stack.\n                </li>\n                <li>\n                  After scanning all the characters of the infix expression,\n                  perform step 2 operation until the operator stack is not\n                  empty.\n                </li>\n                <li>Return the top of operand stack.</li>\n              </ol>\n            </div>\n            <div class=\"my-2 p-2\">\n              <strong>Similar posts:</strong>\n              <a href=\"./stack.html\">Stack</a>\n              |\n              <a href=\"/blogs/infixPrefixPostfixExpressions\"\n                >Infix VS Postfix VS Prefix</a\n              >\n              |\n              <a href=\"/blogs/infixToPostfix\">Infix to Postfix</a>\n              |\n              <a href=\"/blogs/evaluationOfPostfix&Prefix\"\n                >Evaluation of Postfix & Prefix Expressions</a\n              >\n            </div>\n","html":"<div class=\"my-2 p-2\">\n              <p>\n                Lets see the precedence of the operators that will be used to\n                convert the given infix to prefix expression and understand the\n                logic for conversion.\n              </p>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Precedence</h4>\n              <div class=\"table-responsive\">\n                <table class=\"table table-striped\">\n                  <caption class=\"text-center\">\n                    Precedence\n                  </caption>\n                  <thead class=\"thead-dark\">\n                    <tr>\n                      <th>Operator</th>\n                      <th>Stack precedence</th>\n                      <th>Input precedence</th>\n                    </tr>\n                  </thead>\n                  <tbody>\n                    <tr>\n                      <th>+ -</th>\n                      <th>2</th>\n                      <th>1</th>\n                    </tr>\n                    <tr>\n                      <th>/ *</th>\n                      <th>4</th>\n                      <th>3</th>\n                    </tr>\n                    <tr>\n                      <th>^</th>\n                      <th>6</th>\n                      <th>7</th>\n                    </tr>\n                    <tr>\n                      <th>(</th>\n                      <th>0</th>\n                      <th>9</th>\n                    </tr>\n                    <tr>\n                      <th>)</th>\n                      <th>-</th>\n                      <th>0</th>\n                    </tr>\n                  </tbody>\n                </table>\n              </div>\n            </div>\n            <div class=\"my-2 p-2\">\n              <h4>Logic for conversion</h4>\n              <p class=\"text-muted\">\n                Do refer the code available the end of this section to\n                understand the following theory.\n              </p>\n              <ol class=\"pl-4\">\n                <li>\n                  Create two stacks using arrays of type character, one for\n                  operand stack and another one for operator stack.\n                </li>\n                <li>\n                  There occurs a situation to perform the following operation:\n                  <ol class=\"pl-4\">\n                    <li>\n                      Pop the top of operand stack and save it as operand2.\n                    </li>\n                    <li>\n                      Once again pop the top of operand stack and save it as\n                      operand1.\n                    </li>\n                    <li>\n                      Copy the incoming operator into a temporary expression.\n                    </li>\n                    <li>\n                      Concat the operand1 and then operand2 to this temporary\n                      expression.\n                    </li>\n                    <li>\n                      Finally push this temporary expression to the operand\n                      stack.\n                    </li>\n                  </ol>\n                </li>\n                <li>Scan the infix expression from left to right.</li>\n                <li>\n                  If the character read is an operand then push it to the\n                  operand stack.\n                </li>\n                <li>\n                  Else loop until the operator stack is not empty and stack\n                  precedence of top(of operator stack) is more than the input\n                  precedence.\n                  <ol class=\"pl-4\">\n                    <li>\n                      If the input character is ')' then perform step 2\n                      operation until the top of stack is not '('.\n                    </li>\n                    <li>\n                      Pop the top of operator stack because it will obviously be\n                      '(' and break the loop(step 5).\n                    </li>\n                    <li>\n                      Else if the input character is not ')' then perform step 2\n                      operation.\n                    </li>\n                  </ol>\n                </li>\n                <li>\n                  If the step 5 condition fails and input character is not ')'\n                  then push the operator into the operator stack.\n                </li>\n                <li>\n                  After scanning all the characters of the infix expression,\n                  perform step 2 operation until the operator stack is not\n                  empty.\n                </li>\n                <li>Return the top of operand stack.</li>\n              </ol>\n            </div>\n            <div class=\"my-2 p-2\">\n              <strong>Similar posts:</strong>\n              <a href=\"./stack.html\">Stack</a>\n              |\n              <a href=\"/blogs/infixPrefixPostfixExpressions\"\n                >Infix VS Postfix VS Prefix</a\n              >\n              |\n              <a href=\"/blogs/infixToPostfix\">Infix to Postfix</a>\n              |\n              <a href=\"/blogs/evaluationOfPostfix&Prefix\"\n                >Evaluation of Postfix & Prefix Expressions</a\n              >\n            </div>"},"thumbnail":{"childImageSharp":{"fluid":{"tracedSVG":"data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='400'%20height='225'%20viewBox='0%200%20400%20225'%20preserveAspectRatio='none'%3e%3cpath%20d='M24%2090l-1%2012-1%208h11v-9l2%204c2%204%203%205%205%205s2%200%202-9%200-10-2-10c-1%200-2%201-2%203l-1%204-1-3c-3-7-7-6-7%201l-1%206v-6c0-5%200-6-2-6h-2m25%201c-5%200-6%201-6%2013%200%206%200%206%203%206%202%200%202%200%202-3s0-3%203-4c2%200%203-1%203-2%200-2-1-2-3-2-5%200-4-3%201-3l4-3c0-2%200-3-7-2m9-1l-2%2012v8h5c6%200%206%200%207-3l1-2%202%202c0%202%202%203%203%203%202%200%202%200%200-6-1-4-1-4%201-8%202-3%202-3%201-5-2-1-2-1-4%201-2%203-2%203-3%201s-3-3-5-1c-1%201%200%202%201%205l2%203-2%204-3%204v-9c0-9%200-9-2-9h-2m33%201c-5%200-5%200-5%203l2%202c2%200%202%201%202%207%200%207%200%207%203%207%202%200%202%200%202-7%200-8%200-8%203-8%202%200%202%200%202-2-1-3-2-3-9-2m12%202c-5%206-3%2018%204%2017%208-1%209-20%200-20l-4%203m38-2c-3%200-4%202-4%2012%200%206%200%207%202%207s2-1%202-3c0-4%202-4%204%200%201%203%201%203%203%202s2-1%201-4v-4c2-3%201-9-2-10l-2-1-4%201m16%200h-5v4l-1%2010v5h5c6%200%208-1%208-3s-1-2-3-2l-4-1c-1-1%201-2%204-2l2-2c0-2-1-2-3-2-4%200-4-2%201-3%203%200%204-1%204-3l-2-2-6%201m15%200c-6%200-6%200-6%2010%200%208%200%209%202%209s2%200%202-3%200-3%204-4c4%200%205-4%200-4-4%200-4-3%201-4%202%200%203-1%203-2v-2h-6m22%202l-1%202-1-2c-1-2-3-3-5-1-1%201-1%201%201%204%201%204%201%204-1%208-3%205-3%206%200%206l4-2%201-2%202%202c0%201%201%202%203%202s2%200%200-5l-2-5%203-4%202-3-2-2c-1-1-2-1-4%202m-70-1l-2%209v9h2c3%200%203%200%203-3%200-2%201-3%203-4%204-1%207-5%205-9%200-2-1-3-5-3l-6%201m144%2010c-3%203-5%2013-3%2017%201%202%204%203%205%201%201-1-1-9-3-10-4-1%202-9%208-9%207%200%209%205%206%2011-2%205-2%208%200%209%204%201%207-8%204-9l-1-4c0-8-10-12-16-6m31%204l-1%208v7h17l-5%205a66%2066%200%2000-19%2037l-2%2010v1l6-7c7-9%2017-15%2017-10%200%202%201%203%203%203l2-2-1-3h3c3%200%202%201%200%204l-2%204v3h-17v7c0%206%200%207-2%208-3%202-3%203%200%203%202%200%203%204%201%206l-6%201c-9%200-11-4-7-9l2-5c0-3-8%206-8%2010-1%203-1%203-10%204-8%200-8%200-8%202s1%203%205%203c5%200%206%200%204%205-1%202%201%202%2048%202h49l1-4c1-2%202-3%205-3%205-1%205-4%200-5h-3v-14c0-14-1-21-4-21l-2-2-1-2c-7-1-7-4-3-12%207-13%207-17%200-22-4-3-5-4-5-8l-1-4c-1-1-1%201-1%204%200%205%200%205-2%204-3-1-19%200-23%201l-3%201v-10l-14-1-13%201m2%208v6h22v-13h-22v7m-31%2027l1%209h12v-18h-13v9m55%2016c0%201-1%202-3%202s-2%201-2%204v3h6c9%200%209%200%208%207l1%208v2l-1%203c0%204%200%204%205%204%207%201%208%200%208-5l-1-6-2-4-2-5-1-3h-1v-2l-3-5c-1-2-3-3-7-4l-5-2v3m-52%207l-1%205c0%203%200%204-1%203%200-4-2-3-3%200l2%204%202%203%203%201c2%200%202%200%202-3%200-2%200-3%202-3s2-1%202-4l-1-4-1%203c0%204-2%203-2-2-1-3-1-4-4-3'%20fill='%23d3d3d3'%20fill-rule='evenodd'/%3e%3c/svg%3e","aspectRatio":1.7699115044247788,"src":"/static/2ec782c6ebd1969913d43945c5afa7c8/ee604/blog31.png","srcSet":"/static/2ec782c6ebd1969913d43945c5afa7c8/69585/blog31.png 200w,\n/static/2ec782c6ebd1969913d43945c5afa7c8/497c6/blog31.png 400w,\n/static/2ec782c6ebd1969913d43945c5afa7c8/ee604/blog31.png 800w,\n/static/2ec782c6ebd1969913d43945c5afa7c8/f3583/blog31.png 1200w,\n/static/2ec782c6ebd1969913d43945c5afa7c8/e4d72/blog31.png 1280w","sizes":"(max-width: 800px) 100vw, 800px"}}}},"pageContext":{"blog":"infixToPrefix","thumbnail":"thumbnails/blog31.png"}},"staticQueryHashes":["2987289216","63159454"]}