home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / BIPL.ZIP / PROCS.ZIP / JUMPQUE.ICN < prev    next >
Encoding:
Text File  |  1992-11-20  |  895 b   |  34 lines

  1. ############################################################################
  2. #
  3. #    File:     jumpque.icn
  4. #
  5. #    Subject:  Procedure to jump element to head of queue
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     May 9, 1992
  10. #
  11. ###########################################################################
  12. #
  13. #  jumpcue(queue, y) moves y to the head of the queue if it is in queue
  14. #  but just adds y to the head of the queue if it is not already in
  15. #  the queue.  A copy of queue is returned; the argument is not modified.
  16. #
  17. ############################################################################
  18.  
  19. procedure jumpque(queue, y)
  20.    local x
  21.  
  22.    queue := copy(queue)
  23.  
  24.    every 1 to *queue do {        # delete y from queue if it's there
  25.       x := get(queue)
  26.       if x ~=== y then put(queue, x)
  27.       }
  28.  
  29.    push(queue, y)            # insert y at the head of queue
  30.  
  31.    return queue
  32.  
  33. end
  34.