Struktur Data : Ubah Infix Menjadi Postfix

//NAMA : Riyn Winesdyo W
//NIM : 1701292866
//KELAS: 02PPT

#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#define MAX 100

typedef struct stack
{
 int data[MAX];
 int top;
}stack;

int priority(char);
void init(stack *);
int empty(stack *);
int full(stack *);
char pop(stack *);
void push(stack *,char);
char top(stack *);

void main()
{
stack s;
char x;
int token;
init(&s);
clrscr();
printf("nEnter infix expression:");
  while((token=getchar())!='n')
  {
    if(isalnum(token))
       printf("%c",token);
    else
       if(token == '(')
           push(&s,'(');
       else
       {
         if(token == ')')
             while((x=pop(&s))!='(')
             printf("%c",x);
         else
         {
         while(priority(token)top=-1;
}
//---------------------------------------------
int empty(stack *s)
{
    if(s->top==-1)
 return(1);
    else 
 return(0);
}
//---------------------------------------------
int full(stack *s)
{
    if(s->top==MAX-1)
 return(1);
    else 
 return(0);
}
//---------------------------------------------
void push(stack *s,char x)
{
  s->top=s->top+1;
  s->data[s->top]=x;
}
//---------------------------------------------
char pop(stack *s)
{
   int x;
   x=s->data[s->top];
   s->top=s->top-1;
   return(x);
}
//---------------------------------------------
char top(stack * s)
{
   return(s->data[s->top]);
}
//---------------------------------------------

Leave a Reply