next up previous
Next: Sorted List Up: CSE 2320: Algorithms and Previous: Operations

Sorted List

   Insert(L,x)
      Find first object in L
      whose key is greater than key(x).
      Put x just before


   Insert(L,x)
      if head(L) = NIL  or  key(head(L)) >= key(x)
      then next(x) = head(L)
           head(L) = x
      else y = head(L)
           while next(y) <> NIL  and  key(next(y)) < key(x)
              y = next(y)
           next(x) = next(y)
           next(y) = x



\psfig{figure=figures/f12-8.ps}



Copyright © 1998 The University of Texas at Arlington