next up previous
Next: Circular Lists Up: CSE 2320: Algorithms and Previous: Operations

Sorted Double List

Min, Max, Successor, Search: same as for sorted single lists

Predecessor(L,x)
   return prev(x)

Delete(L,x)
   ; same as for unsorted double lists

Insert(L,x)
   if head(L) = NIL
   then head(L) = x                ; list empty
        prev(x) = NIL
        next(x) = NIL
   else if key(head(L)) >= key(x)
        then prev(head(L)) = x     ; first key greater
             next(x) = head(L)
             head(L) = x
             prev(x) = NIL
        else y = head(L)
             while next(y) <> NIL  and  key(next(y)) < key(x)
                y = next(y)
             next(x) = next(y)     ; search for right place
             next(y) = x
             prev(x) = y
             if next(x) <> NIL
             then prev(next(x)) = x



Copyright © 1998 The University of Texas at Arlington