CS 241 Data Structures: Dr. Bashir M. Ghandi
CS 241 Data Structures: Dr. Bashir M. Ghandi
CS 241 Data Structures: Dr. Bashir M. Ghandi
Data Structures
Chapter
Chapter3.2
3.2&&3.7:
3.7:Doubly
DoublyLinked
LinkedList
List
Lists in java.util
LinkedList
ArrayList
Motivation:
The method deleteFromTail() indicates a
problem inherent to singly linked lists:
Nodes in such lists contain no references to their
predecessors. For this reason, we had to scan the
entire list to find the predecessor of the last node,
which is needed to delete the last node.
This scanning process makes deleting from tail
inefficient especially for longer lists.
This and similar problems can be solved by using a
doubly linked list.
Any disadvantage?
tmp
tmp
tmp
tmp
X
tmp
tmp
void clear() Remove all the objects from the array list.
boolean contains(Object ob) Return true if the array list contains the object ob.
void ensureCapacity(int cap) If necessary, increase the capacity of the array list to
accommodate at least cap elements.
T get(int pos) Return the element at position pos; throw
IndexOutOfBoundsException if pos is out of range
int indexOf(Object ob) Return the position of the first occurrence of object ob
in the array list; return -1 if ob is not found.
boolean isEmpty() Return true if the array list contains no elements, false
otherwise
boolean remove(Object ob) Remove the first Occurrence of ob in the array list and
return true if ob was in the array list.
T remove(int pos) Remove the object at position pos; throw
IndexOutOfBoundsException if pos is out of range
T set(int pos, T el) Assign el to position pos and return the object that
occupied this position before the assignment; throw
IndexOutOfBoundsException if pos is out of range.