C++ Programming Tutorial

 
 
 
 
 # include <iostream.h>
 # include   <string.h>
 # include   <stdlib.h>
 # include    <conio.h>

 int top=-1;

 char Stack[25][100]={NULL};

 void push(const char *);
 const char* pop( );

 void postfix_to_infix(const char *);

 int main( )
    {
       clrscr( );

       char Postfix_expression[100]={NULL};

       cout<<\"\\n\\n\\t Enter the Postfix Expression : \";
       cin.getline(Postfix_expression,80);

       postfix_to_infix(Postfix_expression);

       getch( );
       return 0;
    }



 //-----------------------------  push(const char)  ----------------------//


 void push(const char *Symbol)
    {
       if(top==24)
      cout<<\"Error : Stack is full.\"<<endl;

       else
      {
         top++;
         strcpy(Stack[top],Symbol);
      }
    }


 //--------------------------------  pop( )  -----------------------------//


 const char* pop( )
    {
       char Symbol[100]={NULL};

       if(top==-1)
      cout<<\"Error : Stack is empty.\"<<endl;

       else
      {
         strcpy(Symbol,Stack[top]);
         strset(Stack[top],NULL);
         top--;
      }

       return Symbol;
    }


 //---------------------  postfix_to_infix(const char *)  ----------------//


 void postfix_to_infix(const char *Postfix)
    {
       char Infix_expression[100]={NULL};
       char Postfix_expression[100]={NULL};

       strcpy(Postfix_expression,Postfix);
       strcat(Postfix_expression,\"=\");

       int count=0;

       char Symbol_scanned[5]={NULL};

       do
      {
         Symbol_scanned[0]=Postfix_expression[count];

         if(Symbol_scanned[0]==\'/\' || Symbol_scanned[0]==\'*\' ||
        Symbol_scanned[0]==\'-\' || Symbol_scanned[0]==\'+\' ||
                       Symbol_scanned[0]==\'^\' )
        {
           char Value_1[100]={NULL};
           char Value_2[100]={NULL};
           char Result[100]={NULL};

           strcpy(Value_1,pop( ));
           strcpy(Value_2,pop( ));

           if(Infix_expression[(count+1)]!=\'=\')
              strcpy(Result,\"(\");

           strcat(Result,Value_2);
           strcat(Result,Symbol_scanned);
           strcat(Result,Value_1);

           if(Infix_expression[(count+1)]!=\'=\')
              strcat(Result,\")\");

           push(Result);
        }

         else
        push(Symbol_scanned);

         count++;
      }
       while(Postfix_expression[count]!=\'=\');

       strset(Infix_expression,NULL);
       strcpy(Infix_expression,pop( ));

       cout<<\"\\n\\n\\t Infix Expression is : \"<<Infix_expression;
    }

    Related Post:
  1. Program of doubly link list

  2. Program to determine whether the given function is a Cubic Spline or not

  3. Mini Project School Management Application

  4. Program that prints the first 10 integers(using for loop)

  5. Program to search an element in an array using Binary search

  6. Program to draw a line using Bresenhams Line Algorithm (BLA) for lines with slopes positive and less than 1

  7. Program to search an element in an array using Linear search or Sequential Search

  8. Program to draw a line using Digital Differential Analyzer (DDA) Algorithm

  9. Program that provides an example of class

  10. Program that places n equally spaced points on the circumference of a circle of radius r,and then join each point to every other point

  11. Program to show the 3D Shearing Transformation along y-axis

  12. Program to illustrate the Bubble Sort

  13. Program to illustrate an example of Polymorphism ( Pure Virtual functions ).

  14. Program of construction overloading

  15. PROGRAM TO IMPLEMENT RECURSIVE DESCENT PARSER

  16. Program to implement a Translator that reads an Infix Expression translates it into a Postfix Expression and evaluate the Postfix Expression

  17. Demonstrating enum keyword

  18. Program to estimate the Integral value of the function at the given points from the given data using Romberg Method

  19. Program that takes input of vector elements and performs multiplication operation, and input/output (&gt;&gt;, &lt;&lt;) using operator overloading

  20. Program to read a Non-Linear equation in one variable, then evaluate it using Secant Method and display its kD accurate root

 
 
Didn't find what you were looking for? Find more on Program to convert a Postfix Expression into an Infix Expression