Professional Documents
Culture Documents
432 - Pract4-5 - Div A
432 - Pract4-5 - Div A
public:
stack()
{
top=-1;
size=5;
}
bool IsEmpty()
{
if(top==-1)
{
return true;
}
else
{
return false;
}
}
bool IsFull()
{
if(top==size-1)
{
return true;
}
else
{
return false;
}
}
void push(int data)
{
if(IsFull())
{
cout<<"STACK IS FULL..."<<endl;
}
else
{
top++;
arr[top]=data;
}
}
int pop()
{
if(IsEmpty())
{
cout<<"STACK IS EMPTY..."<<endl;
}
else
{
int c;
c=arr[top];
top--;
return c;
}
}
void show()
{
if(IsEmpty())
{
cout<<"STACK IS EMPTY..."<<endl;
}
else
{
for (int i=0;i<=top;i++)
{
cout<<"DATA ---- "<<arr[i]<<endl;
}
}
}
while(i<size)
{
ch=in[i];
w=getweight(ch);
if(w==0)
{
po[k++]=ch;
}
else
{
if(IsEmpty())
{
push(ch);
}
else
{
while(!IsEmpty() && w<=getweight(arr[top]))
{
po[k++]=arr[top];
pop();
}
push(ch);
}
}
i++;
}
while(!IsEmpty())
{
po[k]=arr[top];
k++;
pop();
}
po[k]=0;
}
};
int main()
{
char given[]="1+2*3";
int s=strlen(given);
char desired[s];
stack obj;
obj.in2p(given,desired,s);
cout<<"\n\n\n\t\t----------------------------------------------";
cout<<"\n\t\t| |";
cout<<"\n\t\t| INFIX TO POSTFIX EXPRESSION CONVERTER |";
cout<<"\n\t\t| |";
cout<<"\n\t\t----------------------------------------------\n";
cout<<"\t\tINFIX EXPRESSION = "<<given;
cout<<"\n\n\t\tPOSTFIX EXPRESSION = "<<desired<<endl<<endl;
system("pause");
};
Output: