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 to add, subtract and multiply matrix

  2. Program to interchange the values of two int , float and char using function templates

  3. Program to illustrate the use of pointer this using header file this.h

  4. Program to perform operator overloading converting one class object to another

  5. Program to estimate the value of Third Derivative of the function at the given points from the given data using Central Difference Formula of order 2

  6. Program to read a Linear System of Equations,then evaluate it by using Jacobis Itrative Method and show the result

  7. Program to draw a circle using Polynomial Method

  8. Program to illustrate the use of the break statement

  9. Program to draw an ellipse using Polynomial Method

  10. Program to estimate value of First Derivative of the function at the given points from the given data using Backward Difference Formula , Forward diff

  11. Program that defines template to find minimum value in an array

  12. Program to illustrate the implementation of array as a Circular Queue

  13. Program that takes input of students and result obtained, based on that provides rank

  14. Program to search an element in an array using Linear search

  15. Program that provides an example of passing structure as parameter using call by reference

  16. Program to illustrate the binary operator(+) overloading by creating a new object

  17. Program that reads two numbers from user, computes and display their sum.

  18. write a class to represent a vector (a series of float values)

  19. Program to capitalize the first charcter of every word in a string

  20. Program to perform radix sort

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