Professional Documents
Culture Documents
Lists: CSE 373 Data Structures
Lists: CSE 373 Data Structures
CSE 373
Data Structures
Lecture 3
Readings
• Reading
› Section 3.1 ADT (recall, lecture 1):
• Abstract Data Type (ADT): Mathematical description of an
object with set of operations on the object.
› Section 3.2 The List ADT
0 1 2 3 … count-1 MAX_SIZE-1
A1 A2 A3 A4 … AN
0 1 2 3 4 5 MAX_SIZE-1
A B C D E F
0 1 2 3 4 5 6 MAX_SIZE-1
A B Z C D E F
L node node
Value Next Value Next
NULL
pL
node
node
Value Next
Value Next
NULL
node
node
Value Next
Value Next
P NULL
Value Next
E
header node
first actual list node
Value Next
Value Next
ignore
NULL
node
node
Value Next
Value Next
NULL
P
To delete the node pointed to by P,
need a pointer to the previous node;
See book for findPrevious method
12/26/03 Lists - Lecture 3 17
Doubly Linked Lists
• findPrevious (and hence Delete) is slow [O(N)]
because we cannot go directly to previous
node
• Solution: Keep a "previous" pointer at each
node
null -1
null 1
3427 7 342
+898 +8 +89
Recursive calls
5
10 +1
3427 7 342
-898 -8 -89
Recursive calls
9
-10 -1
1000000 0 100000
-999999 -9 -99999
Recursive calls
1 1
-10 -1
0