Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

More Books

Students also viewed these Databases questions

Question

Find (x) for each function. Then find (0) and (2). f(x) = 2x + 9

Answered: 1 week ago

Question

How do Dimensional Database Models differ from Relational Models?

Answered: 1 week ago

Question

What type of processing do Relational Databases support?

Answered: 1 week ago

Question

Describe several aggregation operators.

Answered: 1 week ago