Presentation is loading. Please wait.

Presentation is loading. Please wait.

Linked lists Singly linked lists Doubly linked lists Circular lists Self-organizing lists LinkedList and ArrayList Data Structures and Algorithms in Java,

Similar presentations


Presentation on theme: "Linked lists Singly linked lists Doubly linked lists Circular lists Self-organizing lists LinkedList and ArrayList Data Structures and Algorithms in Java,"— Presentation transcript:

1 Linked lists Singly linked lists Doubly linked lists Circular lists Self-organizing lists LinkedList and ArrayList Data Structures and Algorithms in Java, Third EditionCh03 – 1

2 Singly linked list node public class SLLNode { public T info; public SLLNode next; public SLLNode() { next = null; } public SLLNode(T el) { info = el; next = null; } public SLLNode(T el, SLLNode p) { info = el; next = p; } el abbreviated as: el Data Structures and Algorithms in Java, Third EditionCh03 – 2

3 Singly linked list SLLNode p; p = new SLLNode (2); p.next = new SLLNode (8); p.next.next = new SLLNode (3); 2 \ p 8 \ 2 p 82 p 3 \ \ \ Data Structures and Algorithms in Java, Third EditionCh03 – 3

4 Singly linked list public class SLL { protected SLLNode head, tail; // methods:........... } head tail // methods: 2 83 \ Data Structures and Algorithms in Java, Third EditionCh03 – 4

5 Singly linked list: insertion at the head 2 83 \ tail 5 head tail null special case: 5 \ head Data Structures and Algorithms in Java, Third EditionCh03 – 5

6 Singly linked list: insertion at the tail 2 83 head tail 5 \ head tail null special case: 5 \ \ Data Structures and Algorithms in Java, Third EditionCh03 – 6

7 Singly linked list: deletion from the head 83 \ tail head tail null special case: \ head 2 3 Data Structures and Algorithms in Java, Third EditionCh03 – 7

8 Singly linked list: deletion from the tail 2 8 \ tail head tail null special case: \ head 3 \ 3 Data Structures and Algorithms in Java, Third EditionCh03 – 8

9 Doubly linked list public class DLL { protected DLLNode head, tail; // methods:........... } head tail // methods: 2 \ 83 \ public class DLLNode { public T info; public DLLNode next, prev; // constructors:........... } Data Structures and Algorithms in Java, Third EditionCh03 – 9

10 Doubly linked list: insertion at the head 2 83 \ tail 5 \ head tail null special case: 5 \ \ head \ Data Structures and Algorithms in Java, Third EditionCh03 – 10

11 Doubly linked list: deletion from the tail 2 \ 8 \ tail head tail null special case: \ \ head 3 \ 3 Data Structures and Algorithms in Java, Third EditionCh03 – 11

12 Self-organizing lists Move‑to‑front method: after the desired element is located, put it at the beginning of the list. A BCDC CABD Transpose method: after the desired element is located, swap it with its predecessor. ABCDC ACBD Data Structures and Algorithms in Java, Third EditionCh03 – 12

13 A 4 B 2 C 2 D 1 C Ordering method: order the list using a criterion natural for information under scrutiny. ABCDC ABCD Count method: order the list by the number of times elements are being accessed. A 4 C 3 B 2 D 1 Self-organizing lists (cont’d) C 2 Data Structures and Algorithms in Java, Third EditionCh03 – 13

14 Self-organizing lists: accessing elements for the first time move-to-front, transpose, and count methods: A BXYP ABXYP ordering method: ABXYP ABPXY Data Structures and Algorithms in Java, Third EditionCh03 – 14

15 Self-organizing lists: example element D A C C B A A plain D DA DAC DACB move-to- front D DA DAC CDA CDAB ACDB trans- pose D DA DAC DCA DCAB DACB ADCB count D1D1 D1A1D1A1 D1A1C1D1A1C1 C2D1A1C2D1A1 C2D1A1B1C2D1A1B1 C2A2D1B1C2A2D1B1 A3C2D1B1A3C2D1B1 ordering D AD ACD ABCD A BC ABC represents the list

16 Priority queue: linked list implementation number of operationsenqueuedequeue unordered list ordered list const n ≤ n const Data Structures and Algorithms in Java, Third EditionCh03 – 16


Download ppt "Linked lists Singly linked lists Doubly linked lists Circular lists Self-organizing lists LinkedList and ArrayList Data Structures and Algorithms in Java,"

Similar presentations


Ads by Google