Anyways, I just found this site because I was looking for a code that does an infix to postfix conversion and I found it here. But that's not the problem.
I'm taking this class at my university called advanced algorithms and data structures. Currently, we have a project due, of which i'm already a week late. The professor has given me until April 5 to complete it. Thing is, I haven't been keeping up with the class because i'm taking 5 other math classes which have been taking up my time along with working for a local arcade.
So i'm here asking you guys desperately. Will one of you guys try to write the code for my project? I am running out of time and I need to pass this class.
Here are the links to the project handout.
pg1 http://img181.images...proj1pg1ky1.jpg
pg2 http://img181.images...proj1pg2vo0.jpg
pg3 http://img181.images...proj1pg3le0.jpg
pg4 http://img72.imagesh...proj1pg4pn6.jpg
pg5 http://img72.imagesh...proj1pg5ip8.jpg
This is the code I found, not sure if this is enough.
// the program is used to convert a infix expression to a postfix expression
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
const int size =50;
char infix[size],postfix[size],stack[size];
int top=-1;
int precedence(char ch); // function to get the precedence of the operator
char pop(); //function to pop an element from the stack
char topelement(); // returns the top element of the stack
void push(char ch); // pushes an element into the stack
int main()
{
char ele,elem,st[2];
int prep,pre,popped,j=0,chk=0;
strcpy(postfix," ");
gets(infix);
for(int i=0;infix[i]!=0;i++)
{
if(infix[i]!='('&&infix[i]!=')'&&infix[i]!='^'&&infix[i]!='*'&&infix[i]!='/'&&infix[i]!='+'&&infix[i]!='-')
postfix[j++]=infix[i];
else if(infix[i]=='(')
{
elem=infix[i];
push(elem);
}
else if(infix[i]==')')
{
while(popped=pop() != '(')
postfix[j++]=popped;
}
else
{
elem=infix[i];
pre=precedence(elem);//stores the precedence of operator coming frm infix
ele=topelement();
prep=precedence(ele);//stores the precedence of operator at the top of the stack
if(pre > prep)
push(elem);
else
{
while(prep >= pre)
{
if(ele=='#')
break;
popped=pop();
ele=topelement();
postfix[j++]=popped;
prep=precedence(ele);
}
push(elem);
}
}
}
while((popped=pop())!='#')
postfix[j++]=popped;
postfix[j]='\0';
cout<<"\n post fix :"<<postfix<<endl;
system("pause");
return 0;
}
int precedence(char ch)
{
switch(ch)
{
case '^' : return 5;
case '/' : return 4;
case '*' : return 4;
case '+' : return 3;
case '-' : return 3;
default : return 0;
}
}
char pop() //function to pop the element from the stack
{
char ret;
if(top!=-1)
{ ret =stack[top];
top--;
return ret;
}
else
return '#';
}
char topelement() // function to return top element from the stack without popping
{
char ch;
if(top!=-1)
ch=stack[top];
else
ch='#';
return ch;
}
void push(char ch) // function to push an element in the stack
{
if(top!=size-1)
{
top++;
stack[top]= ch;
}
}
Thank you.
This post has been edited by jeps1lon: 01 April 2007 - 11:04 PM

New Topic/Question
Reply




MultiQuote






|