Can you tell me if this will work? I'm trying to get the logic down for prefix evaluation using a linklist based queue.
The structure I came up with is:
1) Queue up entire equation.Code:typedef struct queue { char cData; int nData; int flag; /* 1 if char, 2 if number */ struct queue *next; }QUEUE;
2) Check element:
a) If its an operator, check to see if next two are operands, if so, deQueue the two operands.3) Repeat step 2 until only one element is left.
b) Perform the operation.
c) Then put result in the operator's element and change the flag.
d) If two operands are not found, move on to next element, repeat step 2).
4) Display result.



LinkBack URL
About LinkBacks


