#Initialization |
A. Set F[k] ← k + 1 and B[k] ← k − 1, 0 ≤ k < N. |
B. Set up two (FIFO) queues, Q1 and Q2, and put all the numbers, 0, …, N − 1, in order into Q1 while Q2 remains empty. |
C. Define a marker variable m and a flag. |
#Processing |
While (Q1 nonempty){ |
Set m ← 0. |
While (Q1 nonempty){ |
k ← dequeue Q1. |
If(m ≤ k){ |
Set flag ← 0. |
While (F[k] ≠ N and intervals at k and F[k] are adjacent violators){ |
Pool intervals beginning at k and F[k]. |
Set u ← F[F[k]]. |
Redefine F[k] ← u. |
If (u < N) redefine B[u] ← k. |
Update m ← u. |
Update flag ← 1. |
} |
} |
If (flag = 1 and B[k] ≥ 0) enqueue B[k] in Q2. |
} |
Interchange Q1 and Q2. |
} |