Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 16 Section 6.2 Thu, Mar 1, 2007

Similar presentations


Presentation on theme: "Lecture 16 Section 6.2 Thu, Mar 1, 2007"— Presentation transcript:

1 Lecture 16 Section 6.2 Thu, Mar 1, 2007
Array Lists Lecture 16 Section 6.2 Thu, Mar 1, 2007

2 List Implementation We will implement lists in a number of ways
As an array Fixed head Circular As a linked list Singly linked Doubly linked Circularly linked

3 The ArrayList Class An array list is an implementation of the List ADT that uses an array to store the list elements. It is very similar to the Vectr class. Difference: The size is adjustable after the list has been constructed.

4 Data Members int mSize int capacity T* element
The number of elements in the list. int capacity The number of array positions allocated. T* element A pointer to the first array element.

5 The List Elements The list elements a1, ..., amSize are stored in array positions element[0]through element[mSize - 1].

6 Validity Requirements
capacity >= 0. mSize >= 0 and mSize <= capacity. If capacity == 0, then element == NULL. If capacity > 0, then element != NULL.

7 The ArrayList Class arraylist.h ListTest.cpp

8 Circular Array Lists A circular array list is like an ordinary array list, except that the elements may wrap around the ends of the array. This makes it much more efficient to add and remove elements from the front end of the list.

9 Circular Array Lists Dynamics
Begin with an empty list.

10 Circular Array Lists Dynamics
Add six elements at the tail (back). 10

11 Circular Array Lists Dynamics
Add six elements at the tail (back). 10 45

12 Circular Array Lists Dynamics
Add six elements at the tail (back). 10 45 25

13 Circular Array Lists Dynamics
Add six elements at the tail (back). 10 45 25 90

14 Circular Array Lists Dynamics
Add six elements at the tail (back). 10 45 25 90 15

15 Circular Array Lists Dynamics
Add six elements at the tail (back). 10 45 25 90 15 40

16 Circular Array Lists Dynamics
Delete three elements from the head (front). 45 25 90 15 40

17 Circular Array Lists Dynamics
Delete three elements from the head (front). 25 90 15 40

18 Circular Array Lists Dynamics
Delete three elements from the head (front). 90 15 40

19 Circular Array Lists Dynamics
Add one element at the head (front). 60 90 15 40

20 Circular Array Lists Dynamics
Add six elements at the tail (back). 60 90 15 40 65

21 Circular Array Lists Dynamics
Add six elements at the tail (back). 60 90 15 40 65 90

22 Circular Array Lists Dynamics
Add six elements at the tail (back). 60 90 15 40 65 90 35

23 Circular Array Lists Dynamics
Add six elements at the tail (back). 60 90 15 40 65 90 35 20

24 Circular Array Lists Dynamics
Add six elements at the tail (back). 50 60 90 15 40 65 90 35 20

25 Circular Array Lists Dynamics
Add six elements at the tail (back). 50 80 60 90 15 40 65 90 35 20


Download ppt "Lecture 16 Section 6.2 Thu, Mar 1, 2007"

Similar presentations


Ads by Google