Question: I keep getting an error. I was wondering what i was doing wrong. Create your code in p1abc123.c (replace abc123 with your abc123 ID). It

I keep getting an error. I was wondering what i was doing wrong.

Create your code in p1abc123.c (replace abc123 with your abc123 ID). It must not contain the code from the driver!! Based on what the driver calls, you need to create (at least) this function: int convertToPostfix(char *pszInfix, Out out) It returns 0 if it converted successfully. Otherwise, it returns a value which indicates an error in the infix expression (e.g., missing left paren, missing right paren). It populates the out array using the addPostfixOut function (provided in the driver). For modularity, you will need to divide convertToPostfix into multiple functions. To compile the driver, your code, and create an executable, use the make utility

This should be the output

RECIT = N RECIT = Y PROF = CLARK PROF NEVER CLARK PROF ONLY CLARK PROF = CLARK AND RECIT = N PROF NEVER CLARK AND DEPT = CS RECIT = Y AND ( PROF = CLARK OR PROF = GIBSON ) RECIT = Y AND ( PROF = CLARK AND PROF = GIBSON ) LANG ONLY C ( LANG ONLY C OR LANG ONLY JAVA ) AND PREREQ NEVER CS2123 DEPT = CS AND RECIT = N AND LANG = JAVA DEPT = CS AND ( RECIT = Y OR LANG = PYTHON ) AND PROF = CLARK DEPT = CS AND RECIT = Y OR LANG = PYTHON AND PROF = CLARK ( ( ( LANG NEVER JAVA ) ) ) ( DEPT = XX PROF = SMITH ) ( ( DEPT = XX ) ) ) ( ( ) AND DEPT = MAT DEPT EDU = DEPT = DEPT = CS MAT ( DEPT = CS ) AND NEVER MAT DEPT = ( NEVER CS ) DEPT ONLY MAT ( DEPT NEVER CS ) 

int actualConversion(Element element, PostfixOut postfixout, Stack stack){

switch(element.iCategory) { case CAT_OPERAND: addOut(out,element); break;

case CAT_OPERATOR: while (isEmpty(stack) == FALSE && element.iPrecedence < topElement(stack).iPrecedence) //Continuous loop until stack is empty {

addOut(out,pop(stack)); }

push(stack,element); break;

case CAT_LPAREN: push(stack,element); break; case CAT_RPAREN; while(isEmpty(stack) == False && topElement(stack).iCategory != CAT_LPAREN) { addOut(out,pop(stack)); }

if(isEmpty(stack) == TRUE) //For when we didn't fine a '(' { freeStack(stack); return WARN_MISSING_LPAREN; } pop(stack); break; } return 0; }

int remainingStack(Stack stack, PutfixOut putfixout) { while(isEmpty(stack) == FALSE) { if(topElement(stack).iCategory == CAT_LPAREN) //for when an unmaatched '(' is found { freeStack(stack); return WARN_MISSING_RPAREN; } addOut(out,pop(stack)); } return 0; }

convertToPostFix(char * pszInfix,PostfixOut postfixOut) { Stack stack = newStack(); Token szToken;

while((pszInfix = getToken(pszInfix, szToken, MAX_TOKEN + 1))! = 0) { Element element; strcpy(element.szToken,szToken); categorize(& element); //initialize the Elements variable values based on the token string entered }

int i;

i = actualConversion(element, out, stack); if (i< >0) return i; i = remainingStack(stack, out); if(i < >0) return i;

freeStack(stack); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!