java+infix,What does it mean by " item=infix_exp[i++]; " in the following C code?

2016-04-14 16:00:00

0

What does it mean by item=infix_exp[i++]; in the following C code? Line no 21. It is for infix to postfix conversion. As far as I know, here i is array index. But why is it incrementing without any loop?

This is the Code

#include

#include

#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++]; /* HERE */

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();

}

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);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值