on debugging : evaluator stack is successfully reserved in memory but values are not pushed at all! don't know what is wrong ? why aren't the values pushed into stack ? knowing that I used my stack implementation in another program and it worked well !!
void infixTopostfix(char infix[], char postfix[]){
int i,j=0;
Stack_ evaluator = initialize();
for(i=0; infix[i] ; ++i){
if(isdigit(infix[i])) { postfix[j++] = infix[i];}
else {
while(!isempty(evaluator) && precedence(infix[i]<=precedence((char)top(evaluator)))
{postfix[j++] = pop(evaluator);}
push(evaluator,(int)infix[i]); }
} postfix[j++] = '\0';
printf("%s",postfix); }
my stack implementation
#include<stdlib.h>
#include<stdio.h>
#define SIZE 100
typedef struct { int top; int items; } Stack;
Stack initialize() { Stack s=malloc(sizeof(Stack)); s->top=0; s->items=(int) malloc(SIZEsizeof(int)); return s; }
_int isfull(Stack _s) { return s->top >= SIZE ?1:0 ; }
int isempty(Stack *s) { return s->top==0?1:0; }
void push(Stack s,int value) { if(!isfull(s)) s->items[s->top++]=value; else printf("stack is full"); }
_ int pop(Stack _s) { if(!isempty(s)) return s->items[--s->top]; else printf("stack is empty"); return 404; }
int top(Stack* s){ if(isempty(s)) return 0; return (s->items[s->top]); }
No responses yet.