Linkedlist: Writing Generic Llist Additional Options To Llist Linkedlist Collection Class Binary Search
Linkedlist: Writing Generic Llist Additional Options To Llist Linkedlist Collection Class Binary Search
LINKEDLIST
1
We wrote a Linked List that holds a String only
2
Previous Linked List Implementation
3
General Note
4
LLNode - Declaration and
Constructors
• You need to make a generic class
public class GenericLLNode<T> {
private T data;
private GenericLLNode<T> next;
public GenericLLNode() {
this.data = null;
this.next = null;
}
public GenericLLNode (T newData) {
this.data = newData;
this.next = null;
}
5
LLNode - Methods
6
LList - Declaration and Constructor
7
Example
8
Example Continued
OUTPUT:
After delete, the String list is
George
Linda
The one deleted is...Henry
9
Example 2
10
Example 2 Continued
11
Extra Practice
12
ADDITIONAL OPTIONS TO
LLIST
13
Single Linked list - Traditional
14
Single Linked List – Options for
Improvements
• Data member – tail – reference to last
node in the list
• Allows add at tail – O(1)
• All other methods same
• Data member - numItems in list
• Can provide useful information without having
to traverse list to count
15
Double Linked List
16
DOUBLY LINKED LIST
17
Node Class
18
DLList Class
public DLList() {
head = null;
tail=null;
}
19
DLList Class (2)
20
Use DLList in Main
21
Delete a Node
22
Search and Delete
23
Practice…..write these methods
24
LINKEDLIST COLLECTION
CLASS
25
LinkedList Collection Class
26
Collection Methods
27
Collection Methods (2)
29
Collection Class Example
30
Collection Class Example (2)
31
Collection Class Example (3)
OUTPUT:
The list is also:
Linda
George
32
QUESTIONS?
33
Release info
• Release: 10/06/2020
• Author: Melissa Sienkiewicz
• Credits/References:
• Linda Crane
• Rex Woollard
• Deitel, P. | Deitel, H.. (2014). Java How To
Program (Early Objects) (10th Edition)
34