Lecture6-OrderedLists

Lecture6-OrderedLists - Lecture 6 Ordered Lists 6.1 This...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
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
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 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
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

Lecture6-OrderedLists - Lecture 6 Ordered Lists 6.1 This...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online