summaryrefslogtreecommitdiff
path: root/ipl/procs/jumpque.icn
blob: 5389ed9c4dddfa591f4132d9bc0cd4f016b428b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
############################################################################
#
#	File:     jumpque.icn
#
#	Subject:  Procedure to jump element to head of queue
#
#	Author:   Ralph E. Griswold
#
#	Date:     May 9, 1992
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  jumpque(queue, y) moves y to the head of the queue if it is in queue
#  but just adds y to the head of the queue if it is not already in
#  the queue.  A copy of queue is returned; the argument is not modified.
#
############################################################################

procedure jumpque(queue, y)
   local x

   queue := copy(queue)

   every 1 to *queue do {		# delete y from queue if it's there
      x := get(queue)
      if x ~=== y then put(queue, x)
      }

   push(queue, y)			# insert y at the head of queue

   return queue

end