I am writing a program for a data structures class in which we are using pre-written functions from the teacher (and I use that term loosely) and we are to basicly build the main driver loop. I have run into a problem in which the struct does not seem to be acting as it should. I get a lot of errors and warnings when trying to complile about it not seeing elements of the structure itself.
Can someone take a look at this and see if there are any glaring mistakes...(some of the last function is not written yet but that is the least of my issue).
Code://*************************************************************************** #include <stdio.h> #include <conio.h> #define TRUE 1 #define FALSE 0 #define MAXQUEUE 5 /* The Queue is declared as a Structure with three members: item, front and back. Front & back keeps track of the index values of Queue for circular reference and array items is used for storage of the items */ struct stack { int front,rear; int items [MAXQUEUE]; }; /* Prototypes */ void initQ (struct queue *pq); int emptyQ (struct queue *pq); void insertQ (struct queue *pq, int x); int removeQ (struct queue *pq); int EvenOdd (int x); int flushQ (int temp[]); /* Main Program */ //*************************************************************************** int main (void) { char response; // for driving main program loop int numb,front,rear,items; // for holding numbers int temp[MAXQUEUE]; // holds items for final print struct stack pq; // Stack 'pq' used to store numbers initQ (&pq); // Call to initialize the stack clrscr(); // Clear the screen // ask to start the program... if '!y' exit fflush (stdin); printf("\n\n\nDo you want to enter items into the Queue? (y/n) > "); scanf("%c", &response); while (response == 'y') { clrscr(); // Clear the screen printf("\nEnter a number..."); printf("\n **NOTE** whole numbers only (no decimal points) "); fflush (stdin); scanf("%d",numb); //Evaluate Inputed Number for Odd or Even and Process items=EvenOdd(numb); if (items < 0) { insertQ(&pq,items); printf("\n\n\t %d Inserted",items); } else { items = removeQ (&pq); //take front number from the queue if (items < 0) printf("\n\n\t\t Queue is Empty - No Deletion Possible."); printf("\n %d Deleted",items); } fflush (stdin); printf("\n\n\n\t Do you want to enter another number? (y/n) > "); scanf("%c", &response); } numb=flushQ(&temp); if (numb < 0) { clrscr(); printf("Nothing Left in the Queue"); } else { clrscr(); printf("\n\t\t Number of Items left in the Queue is %d",items); printf("\n\t\t Front Item is %d",front); printf("\n\t\t Back Item is %d",rear); } printf("\n\n\n PROGRAM TERMINATED"); return 1; } // FUNCTION CALLS /***************************************************************************/ /* This function initializes the Queue */ void initQ (struct queue *pq) { pq->front = MAXQUEUE-1; pq->rear = MAXQUEUE -1; return; } /* This function checks if the queue is empty */ int emptyQ (struct queue *pq) { if (pq->front == pq->rear) return (TRUE); else return (FALSE); } /* This function will insert items into the queue */ void insertQ (struct queue *pq, int x) { int temp; temp = pq->rear ; if (pq->rear == MAXQUEUE-1) pq->rear = 0; else (pq->rear)++; /* Chech for overflow */ if (pq->rear == pq->front) { printf("%d Could not be inserted-Queue is Full\n",x); pq->rear = temp; } else pq->items[pq->rear] = x; return; } /* This function will remove items from the queue (If queue is empty it returns 0, else it removes the front item and returns it's value) */ int removeQ (struct queue *pq) { if (empty(&pq) == TRUE ) { return 0; } else if (pq->front == MAXQUEUE-1) pq->front = 0; else (pq->front)++; return(pq->items[pq->front]); } /* This function checks if number is Odd or Even If odd return -1 else return number inputed */ int EvenOdd (int x) { if (x%2>0) { // odd if there is a remainder return -1; // return odd } return x; // return number given } /* This function checks if number is Odd or Even If odd return -1 else return number inputed */ int flushQ (int temp[]) { int x; x=remove(&pq); // remove front number and stores it if (x < 0) return -1; else { front = x; items++; } // may drive this with a for loop rear=remove(&pq); if (rear<0) // stack is empty { printf("\n\n The Total number of items in the queue are... ",items); printf("%d, ",front); return 1; } return 2; }



LinkBack URL
About LinkBacks


