home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / armbob / armbob_1 / ARMBOB / !ArmBob / progs / h / queue < prev    next >
Encoding:
Text File  |  1995-04-05  |  531 b   |  34 lines

  1. /* queue class        GCW  23/01/95  */ 
  2.  
  3. class queue
  4. {
  5.  front, rear;
  6.  add(x);        // add an item to the rear
  7.  /* get() returns nil from an empty queue  */
  8.  get();         // remove an item from the front
  9. }
  10.  
  11. queue::queue()
  12. {
  13.  front = rear = nil;
  14.  return this;
  15. }
  16.  
  17. queue::add(x)
  18. {
  19.  if (typeof(rear))
  20.    rear = (rear[1] = vector { x; nil; });
  21.  else
  22.    front = rear = vector { x; nil; };
  23. }
  24.  
  25. queue::get()
  26. {
  27.  local item;
  28.  if (!typeof(front)) return nil;
  29.  item = front[0];
  30.  if (!typeof(front = front[1])) rear = nil;
  31.  return item;
  32. }
  33.  
  34.