Eun
2011-03-29 12:09:16 UTC
#define MAX_QUEUE_CAPACITY 10
/* List of valid shapes which could be displayed in the shapes cloud */
typedef enum shapes { rectangle, square, ellipse, circle } Shapes;
/* Each item in the queue will be a shape with a count of the number of times
the shape appears in the input data. */
typedef struct queueItem
{
Shapes tagShape;
int tagCounter;
} NameWeight;
/* The queue uses an array of fixed size to store the items. */
typedef struct queue
{
int currentQueueSize;
int queueFrontIndex;
int queueRearIndex;
NameWeight currentQueueItems[ MAX_QUEUE_CAPACITY ];
} Queue;
/* Queue currently in use by program */
Queue shapesCloud;
/* Key queue operations */
void enqueue( QueueItem ); /* Adds an item to the rear of the queue */
NameWeight dequeue(); /* Removes an item from the front of the queue */
int main( void )
{
//write code here
//need 2 que items, 1 input that loops, 1 to store the output of q.
int counter;
NameWeight person;
for (counter = 0, counter < MAX_QUEUE_CAPACITY, counter++)
{
scanf( "%s", &person.tagShape);
scanf( "%f", &person.tagCounter);
enqueue (person);
}
printf("The queue is...");
for (counter = 0, counter < MAX_QUEUE_CAPACITY, counter++)
{
printf( "%s \n", shapesCloud.currentQueueItems);
}
//need for loop 2 scan input, scan AND q it
//after the loop it needs 2 be de qued, deque = dequeue()
//print result
}
void enqueue( QueueItem item )
{
/* Do not add if the queue is full */
if ( shapesCloud.currentQueueSize >= MAX_QUEUE_CAPACITY ) return;
/* Add new item and increment queue size counter */
shapesCloud.currentQueueItems[ shapesCloud.queueRearIndex ] = item;
shapesCloud.currentQueueSize++;
/* Move the rear index to the right and wraparound if end of the array is reached */
shapesCloud.queueRearIndex++;
if ( shapesCloud.queueRearIndex >= MAX_QUEUE_CAPACITY )
shapesCloud.queueRearIndex = shapesCloud.queueRearIndex - MAX_QUEUE_CAPACITY;
}
QueueItem dequeue()
{
NameWeight item = { rectangle, 0 };
/* Nothing to return if the queue is empty */
if ( shapesCloud.currentQueueSize < 1 ) return item;
/* Return the item at the front position and decrement the queue size counter */
item = shapesCloud.currentQueueItems[ shapesCloud.queueFrontIndex ];
shapesCloud.currentQueueSize--;
/* Move the front index to the right and wraparound if the end of the array is reached */
shapesCloud.queueFrontIndex++;
if ( shapesCloud.queueFrontIndex >= MAX_QUEUE_CAPACITY )
shapesCloud.queueFrontIndex = shapesCloud.queueFrontIndex - MAX_QUEUE_CAPACITY;
/* Return the found item */
return item;
}
input = gary 10 bo 4 heknm 4 kgj 1 jyugfo 78 jkhf 23 kjhv 11
Error: : In function 'main':
Line 36 ERROR: expected expression before '/' token
compilation terminated due to -Wfatal-errors.