Here is the proof – His departing words part 2

…that he did evthing from heart…even programming. Search for something in this C++ program.

 

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

const int SZ = 20 ;

class stack
   {
    int st[SZ] ;
    int top ;

    public :
 stack()                    { top = -1 ; }
 void push(int c)           { st[++top] = c ; }
 int pop()                  { return st[top–] ; }

     } ;

void main()
   {
    stack s ;
    int a, b ;
    char ch ;
    clrscr() ;

    cout << “Enter the postfix expression\n” ;
    while((ch = getche()) != ‘\r’)
       {
 if(ch >= 48 && ch <= 57)
     {
      s.push(ch – ‘0’) ;
      cout << ” ” ;
      continue ;
     }

  b = s.pop() ;
  a = s.pop() ;

 switch(ch)
    {
     case ‘+’ :
        s.push(a + b) ;
        break ;
     case ‘-‘ :
        s.push(a – b) ;
        break ;
     case ‘*’ :
        s.push(a * b) ;
        break ;
    case ‘/’ :
        s.push(a / b) ;
        break ;
    default:
        cout << “U entered illeagal value fucker !” ;
    }

 cout << ” ” ;
      }
       cout << “\nAns. ” << s.pop() ;
       getch() ;
       }

Leave a Reply

Your email address will not be published.