Close
Register
Close Window

Show Source |    | About   «  5.2. The List ADT   ::   Contents   ::   5.4. Linked Lists  »

5.3. Array-Based List Implementation

5.3.1. Array-Based List Implementation

Here is an implementation for the array-based list, named AList. AList inherits from the List ADT,and so must implement all of the member functions of List.


Settings

Proficient Saving... Error Saving
Server Error
Resubmit

Settings

Proficient Saving... Error Saving
Server Error
Resubmit

5.3.1.1. Insert

Because the array-based list implementation is defined to store list elements in contiguous cells of the array, the insert, append, and remove methods must maintain this property.

Settings

Proficient Saving... Error Saving
Server Error
Resubmit

5.3.1.2. Insert Practice Exericse

5.3.2. Append and Remove

Settings

Proficient Saving... Error Saving
Server Error
Resubmit

Removing an element from the head of the list is similar to insert in that all remaining elements must shift toward the head by one position to fill in the gap. If we want to remove the element at position \(i\), then \(n - i - 1\) elements must shift toward the head, as shown in the following slideshow.

Settings

Proficient Saving... Error Saving
Server Error
Resubmit

In the average case, insertion or removal each requires moving half of the elements, which is \(\Theta(n)\).

5.3.2.1. Remove Practice Exericise

Aside from insert and remove, the only other operations that might require more than constant time are the constructor and clear. The other methods for Class AList simply access the current list element or move the current position. They all require \(\Theta(1)\) time.

5.3.3. Array-based List Practice Questions

   «  5.2. The List ADT   ::   Contents   ::   5.4. Linked Lists  »

nsf
Close Window