TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Joe Wilson
NA
7.8k
437.1k
Why does the compiler give error to my Code?
Oct 13 2014 5:08 AM
This is my code:
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <stdio.h>
#define max 30
char pop(void);
void push(char);
int Isunder(void);
int Isover(void);
int prio(char);
int top=-1,i=0,j=0;
char stk[max];
char infix[max];
char postfix[max];
void main()
{
cout << "Please enter your expression in infix form :";
cin >> infix ;
for(i=0;infix[i]!='\0';i++)
{
switch(infix[i])
{
case '(' :
push( '(' );
break;
case ')' :
while(stk[top]!='(')
postfix[j++]=pop();
if (stk[top]=='(')
top--;
break;
case '/':
case '*':
case '+':
case '-':
case '^':
if (!Isunder())
{
if (prio(infix[i]) > prio(stk[top]) )
{
push(infix[i]);
}
else
{
postfix[j++]=pop();
push(infix[i]);
}
}
else
push(infix[i]);
break;
default :
postfix[j++] = infix[i] ;
}
}
while (!Isunder())
postfix[j++]=pop();
postfix[j]='\0';
cout << endl << "Your postfix expression is :" << postfix << endl ;
}
//// pop opertation
char pop()
{
if (!Isunder())
return stk[top--];
}
//// push operation
void push(char ch)
{
if (!Isover())
stk[++top]=ch;
else
cout << "Stack is full";
}
//// overflow
int Isover()
{
if (top == max-1)
return 1;
else
return 0;
}
//// underflow
int Isunder()
{
if (top == -1)
return 1;
else
return 0;
}
/////////////////////////////
int prio(char ch)
{
switch(ch)
{
case '(' :
return 1;
break;
case '-' :
return 2;
break;
case '+' :
return 3;
break;
case '*' :
return 4;
break;
case '/' :
return 5;
break;
case '^':
return 6;
}
}
Reply
Answers (
1
)
How to dispose an object created by FileInfo class
Transfer data between TreeViews