comparison CircularQueue.c @ 1:a8a8fe374984

Subversion era
author Eric Wing <ewing . public |-at-| gmail . com>
date Wed, 27 Oct 2010 16:51:16 -0700
parents 01e39f9f58d5
children 279d0427ef26
comparison
equal deleted inserted replaced
0:01e39f9f58d5 1:a8a8fe374984
264 fprintf(stderr, "%d ", queue->internalQueue[i]); 264 fprintf(stderr, "%d ", queue->internalQueue[i]);
265 } 265 }
266 fprintf(stderr, "\n"); 266 fprintf(stderr, "\n");
267 } 267 }
268 268
269 unsigned int CircularQueueUnsignedInt_ValueAtIndex(CircularQueueUnsignedInt* queue, unsigned int the_index)
270 {
271 unsigned int i;
272 if(NULL == queue)
273 {
274 return 0;
275 }
276 if(the_index >= queue->currentSize)
277 {
278 return 0;
279 }
280 i = (queue->headIndex + the_index) % queue->currentSize;
281 // fprintf(stderr, "%d\n", queue->internalQueue[i]);
282 return queue->internalQueue[i];
283 }
284
269 /* 285 /*
270 * Implementation for void* version starts here. 286 * Implementation for void* version starts here.
271 */ 287 */
272 288
273 CircularQueueVoid* CircularQueueVoid_CreateQueue(unsigned int max_size) 289 CircularQueueVoid* CircularQueueVoid_CreateQueue(unsigned int max_size)
483 queue->currentSize = 0; 499 queue->currentSize = 0;
484 queue->headIndex = 0; 500 queue->headIndex = 0;
485 queue->tailIndex = 0; 501 queue->tailIndex = 0;
486 } 502 }
487 503
488 /* Not implemented for void* */
489 /*
490 void CircularQueueVoid_Print(CircularQueueVoid* queue) 504 void CircularQueueVoid_Print(CircularQueueVoid* queue)
491 { 505 {
492 unsigned int i; 506 unsigned int i;
493 unsigned int count; 507 unsigned int count;
494 if(NULL == queue) 508 if(NULL == queue)
500 { 514 {
501 if(i >= queue->maxSize) 515 if(i >= queue->maxSize)
502 { 516 {
503 i=0; 517 i=0;
504 } 518 }
505 fprintf(stderr, "%d ", queue->internalQueue[i]); 519 fprintf(stderr, "%x ", (unsigned int)queue->internalQueue[i]);
506 } 520 }
507 fprintf(stderr, "\n"); 521 fprintf(stderr, "\n");
508 } 522 }
509 */ 523
510 524 void* CircularQueueVoid_ValueAtIndex(CircularQueueVoid* queue, unsigned int the_index)
511 525 {
512 526 unsigned int i;
527 if(NULL == queue)
528 {
529 return NULL;
530 }
531 if(the_index >= queue->currentSize)
532 {
533 return NULL;
534 }
535 i = (queue->headIndex + the_index) % queue->currentSize;
536 // fprintf(stderr, "%d\n", queue->internalQueue[i]);
537 return queue->internalQueue[i];
538 }
539
540