#include<stdio.h>
#include<conio.h>
#define SIZE 100
int top = -1;
char stack[SIZE];
void push(char item);
char pop();
int is_operator(char symbol);
int precedence(char symbol);
void main()
{
 int i;
 int j;
 char infix_exp[SIZE], postfix_exp[SIZE];
 char item;
 char x;
 printf("\nEnter Infix expression in parentheses: \n");
 gets(infix_exp);
 i=0;
 j=0;
 item=infix_exp[i++];
 while(item != '\0')
 {
  if(item == '(')
  {
   push(item);
  }
  else if((item >= 'A'  && item <= 'Z') ||
  (item >= 'a' && item <= 'z'))
  {
   postfix_exp[j++] = item;
  }
  else if(is_operator(item) == 1)
  {
   x=pop();
   while(is_operator(x) == 1 && precedence(x)
    >= precedence(item))
   {
    postfix_exp[j++] = x;
    x = pop();
   }
   push(x);
   push(item);
  }
  else if(item == ')')
  {
   x = pop();
   while(x != '(')
   {
    postfix_exp[j++] = x;
    x = pop();
   }
  }
  else
  {
   printf("\nInvalid Arithmetic Expression.\n");
   getch();
   exit(0);
  }
  item = infix_exp[i++];
 }
  postfix_exp[j++] = '\0';
  printf("\nArithmetic expression in Postfix notation: ");
  puts(postfix_exp);
 getch();
}
void push(char item)
{
 if(top >= SIZE-1)
 {
  printf("\nStack Overflow. Push not possible.\n");
 }
 else
 {
  top = top+1;
  stack[top] = item;
 }
}
char pop()
{
 char item = NULL;
 if(top <= -1)
 {
  printf("\nStack Underflow. Pop not possible.\n");
 }
 else
 {
  item = stack[top];
  stack[top] = NULL;
  top = top-1;
 }
 return(item);
}
int is_operator(char symbol)
{
 if(symbol == '^' || symbol == '*' || symbol == '/' ||
 symbol == '+' || symbol == '-')
 {
  return 1;
 }
 else
 {
  return 0;
 }
}
int precedence(char symbol)
{
 if(symbol == '^')
 {
  return(3);
 }
 else if(symbol == '*' || symbol == '/')
 {
  return(2);
 }
 else if(symbol == '+' || symbol == '-')
 {
  return(1);
 }
 else
 {
  return(0);
 }
}

asked 18 May '15, 17:09

Golam%20Kibria%20Sajib's gravatar image

Golam Kibria Sajib
478

closed 18 May '15, 18:32

__salman__'s gravatar image

__salman__ ♦♦
1.1k211

2

প্রশ্নটি ভালো হয়নি। কারন: ১। কোড ফরম্যাটিং করা হয়নি, ২। বাংলা লেখা ইংরেজি অক্ষরে, ৩। এই কোড কি কাজ করে লেখা নাই, ৪। কোডের পরিমান অনেক পুরা প্রগ্রামটা পেস্ট না করে শুধু প্রবলেম পার্টটা দিতে হবে।
**তুমি এই সাইটে ১১টি প্রশ্ন করেছ কিন্তু এখনো কোড ফরম্যাটিং করতে পারনা ব্যপারটা দুঃখজনক।

(18 May '15, 18:27) __salman__ ♦♦

The question has been closed for the following reason "Question is bellow standard quality." by __salman__ 18 May '15, 18:32

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×15
×11

question asked: 18 May '15, 17:09

question was seen: 1,069 times

last updated: 18 May '15, 18:32