home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / sampl254.zip / gcc2 / samples / sample5 / Queue.m < prev    next >
Text File  |  1993-11-07  |  630b  |  47 lines

  1.  
  2. // Queue.m - comp.lang.objective-c simple sample Objective-C program
  3.  
  4. #import "Queue.h"
  5.  
  6. @implementation    Queue
  7.  
  8. + new
  9. {
  10.     self = [super new];
  11.     head = tail = 0;
  12.     qsize = 0;
  13.     return self;
  14. }
  15.  
  16. - empty
  17. {
  18.     while([self size])
  19.     [[self get] free];
  20.     return self;
  21. }
  22.  
  23. - put: anItem
  24. {
  25.   if (tail)
  26.     tail = [[tail set_next : [Node new : anItem]] next];
  27.   else
  28.     head = tail = [Node new : anItem];
  29.   ++qsize;
  30.     return self;
  31. }
  32.  
  33. - get
  34. {
  35.   id contents;
  36.   id old_head = head;
  37.   head = [head next];
  38.   contents = [old_head free];
  39.   if (--qsize == 0)
  40.       tail = head;
  41.   return contents;
  42. }
  43.  
  44. - (unsigned) size { return qsize; }
  45.  
  46. @end
  47.