Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
#include <stdlib.h>
#include<string.h>
#define MaxSize 50
char stack[MaxSize];
int TOP=-1;
//function to insert an element into a stack
void push(char symbol)
{
TOP=TOP+1;
stack[TOP]=symbol;
}
//function to delete an element from a stack
char pop()
{
char k;
k=stack[TOP];
TOP=TOP-1;
return k;
}
//function to check whether the symbol is operand or not
int isoperand(char symbol)
{
if(symbol>='a'&& symbol<='z')
return 1;
else
return 0;
}
//function to check whether the symbol is operator or not
int isoperator(char symbol)
{
if(symbol=='+'|| symbol=='-'|| symbol=='*'|| symbol=='/'|| symbol=='$')
return 1;
else
return 0;
}
//function to assign precedence to all operators
int precedence(char symbol)
{
int result;
switch(symbol)
{
case '(':
result=0; break;
case '+':
case '-':result=1; break;
case '*':
case '/':result=2; break;
}
return result;
}
//to find the reverse of an expression
void rev(char str[])
{
int l, i,j;
char t;
l=strlen(str);
for(i=0,j=l-1;i<l/2;i++,j--)
{
t=str[i];
str[i]=str[j];
str[j]=t;
}
for(i=0;str[i]!=' ';i++)
{
if (str[i]=='(')
str[i]=')';
else
{
if(str[i]==')')
str[i]='(';
}
}
}
// main function
int main()
{
char infix[MaxSize],postfix[MaxSize];
char symbol,temp;
int i,j;
i=j=0;
printf("Enter an infix expression: ");
gets(infix);
rev(infix);
push('(');
while (infix[i]!=' ')
{
symbol=infix[i];
if(isoperand(symbol))
{
postfix[j]=symbol;
//printf("Postfix expression P is: %c n",postfix[i]);
j=j+1;
}
if(symbol=='(')
{
push(symbol);
}
if(isoperator(symbol))
{
while(precedence(stack[TOP])>=precedence(symbol))
{
temp=pop();
postfix[j]=temp;
j=j+1;
}
push(symbol);
}
if(symbol==')')
{
while(stack[TOP]!='(')
{
temp=pop();
postfix[j]=temp;
j=j+1;
}
temp=pop();
}
i=i+1;
}//while loop ends here
while(stack[TOP]!='(')
{
temp=pop();
postfix[j]=temp;
j=j+1;
}
postfix[j]=' ';
printf("Postfix expression is: %s n",postfix);
rev(postfix);
printf("Prefix expression is: %s n",postfix);
return 0;
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team