home *** CD-ROM | disk | FTP | other *** search
- /*Objective_C Implementation of the Queue Class: Queue.m*/
-
- #import <stdio.h>
- #import "Queue.h"
-
- @implementation Queue
-
- //Initialize a Queue instance of floating point elements
- -init
- {
- return [self initCount:0 elementSize:sizeof(float) description:"f"];
- //return id of newly created Queue instance
- }
-
- //Add an element to the queue
- -enQueue: (float)aNumber
- {
- [self addElement: &aNumber];
- return self;
- }
-
- //Remove an element from the Queue
- -deQueue: (float *)aNumber
- {
- if (numElements != 0) {
- *aNumber = *((float *)[self elementAt:0]);
- [self removeElementAt:0]; /* This also automatically shifts all the */
- /* elements between index and the end of */
- /* the queue to close the gap*/
- } else
- *aNumber = 0.0; //Empty queue returns zero
-
- return self;
- }
-
- //Print the elements in the queue
- -printQueue
- {
- int i=0;
-
- if (numElements == 0)
- printf("Queue is empty.\n");
- else {
- printf("%i elements in queue, last in to first:\n", numElements);
- //numElements is an instance variable inherited from the Storage class
- for(i=(numElements-1);i>=0;--i)
- printf(" %f\n", *((float *)[self elementAt:i]));
- }
- return self;
- }
-
- @end
-