This preview shows pages 1–3. Sign up to view the full content.
1
6.1
Lecture 6
–
Ordered Lists
Feb 2008
•
This lecture presents
ordered lists
. An ordered list is
one which is maintained in some predefined order,
such as alphabetical or numerical order.
•
We’ll study a ordered linked list implementation.
•
We’ll consider routines that can,
•
insert
a new element, maintaining the order, and
•
delete
an element from the list.
•
We’ll also consider
lookup
, a routine to extract
information from the list.
6.2
Lecture 6
–
Ordered Lists
Feb 2008
•
A list is numerically ordered if, for every item X in the list, every
item after X in the list is greater than X or equal to X.
•
So the following list is ordered (in ascending order).
•
But the following list is not.
12
45
93
NULL
hdList
45
12
93
NULL
hdList
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document2
6.3
Lecture 6
–
Ordered Lists
Feb 2008
•
Suppose
we
want
to
insert
57
into
the
list,
maintaining
its
ascending order.
•
We search along the list until we find the first item which is greater
than
57
.
•
This is the 3
rd
entry on the list, i.e. the entry for
93
.
•
We want to insert
57
before
this item.
12
45
93
NULL
hdList
57
6.4
Lecture 6
–
Ordered Lists
Feb 2008
•
Step 2: Identify where to insert (before
93
)
•
Step 3: Make
57
point to
93
•
Step 1: we create a new
node for
57
12
45
93
NULL
hdList
57
newNode
57
newNode
12
45
93
NULL
hdList
This is the end of the preview. Sign up
to
access the rest of the document.
 Fall '07
 cheung

Click to edit the document details