0% found this document useful (0 votes)
13 views3 pages

DSL PR 10

Uploaded by

tg467900
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

DSL PR 10

Uploaded by

tg467900
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Practical No.

10

Title : Implement C++ program for expression conversion as infix to postfix and its evaluation
using stack based on given conditions:

1. Operands and operator, both must be single character.

2. Input Postfix expression must be in a desired format.

3. Only '+', '-', '*' and '/ ' operators are expected.

Code :-

#include<iostream>

using namespace std;

char stack[20];

int top=-1;

char postfix[20];

void expconver()

char infix[20];

int i=0;

int j=0;

cout<<"Enter Your Expression: ";

cin>>infix;

for(i=0;infix[i]!='\0';i++)

if(infix[i]=='(' || infix[i]=='[' || infix[i]=='{' )

top++;

stack[top]=infix[i];
}

else if(infix[i]=='a' || infix[i]=='b' || infix[i]=='c' || infix[i]=='d')

postfix[j]=infix[i];

j++;

else if(infix[i]=='+' || infix[i]=='-' || infix[i]=='*')

top++;

stack[top]=infix[i];

else

switch(infix[i])

case ')':while(stack[top]!='(')

postfix[j]=stack[top];

j++;

top--;

top--;

break;

case ']':while(stack[top]!='[')

postfix[j]=stack[top];

j++;

top--;
}

top--;

break;

case '}':while(stack[top]!='{')

postfix[j]=stack[top];

j++;

top--;

top--;

break;

postfix[j]='\0';

cout<<"The Postfix Expression Is: "<<postfix;

int main()

expconver(); // Function Calling

return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy