Top Banner
Doubly Linked Lists 3/18/14 1 Doubly Linked Lists 1 Doubly Linked Lists © 2014 Goodrich, Tamassia, Goldwasser Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Doubly Linked Lists 2 Doubly Linked List A doubly linked list can be traversed forward and backward Nodes store: element link to the previous node link to the next node Special trailer and header nodes prev next element trailer header nodes/positions elements node © 2014 Goodrich, Tamassia, Goldwasser
4

Doubly Linked Lists - Lehman Collegecomet.lehman.cuny.edu › sfakhouri › teaching › cmp › cmp338... · Doubly Linked Lists 3/18/14 2 Doubly Linked Lists 3 Insertion ! Insert

May 30, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Doubly Linked Lists - Lehman Collegecomet.lehman.cuny.edu › sfakhouri › teaching › cmp › cmp338... · Doubly Linked Lists 3/18/14 2 Doubly Linked Lists 3 Insertion ! Insert

Doubly Linked Lists 3/18/14

1

Doubly Linked Lists 1

Doubly Linked Lists

© 2014 Goodrich, Tamassia, Goldwasser

Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014

Doubly Linked Lists 2

Doubly Linked List q  A doubly linked list can be traversed

forward and backward q  Nodes store:

n  element n  link to the previous node n  link to the next node

q  Special trailer and header nodes

prev next

element

trailer header nodes/positions

elements

node

© 2014 Goodrich, Tamassia, Goldwasser

Page 2: Doubly Linked Lists - Lehman Collegecomet.lehman.cuny.edu › sfakhouri › teaching › cmp › cmp338... · Doubly Linked Lists 3/18/14 2 Doubly Linked Lists 3 Insertion ! Insert

Doubly Linked Lists 3/18/14

2

Doubly Linked Lists 3

Insertion q  Insert a new node, q, between p and its successor.

A B X C

A B C

p

A B C

p

X

q

p q

© 2014 Goodrich, Tamassia, Goldwasser

Doubly Linked Lists 4

Deletion q  Remove a node, p, from a doubly linked list.

A B C D

p

A B C

D

p

A B C © 2014 Goodrich, Tamassia, Goldwasser

Page 3: Doubly Linked Lists - Lehman Collegecomet.lehman.cuny.edu › sfakhouri › teaching › cmp › cmp338... · Doubly Linked Lists 3/18/14 2 Doubly Linked Lists 3 Insertion ! Insert

Doubly Linked Lists 3/18/14

3

Doubly-Linked List in Java

© 2014 Goodrich, Tamassia, Goldwasser Doubly Linked Lists 5

Doubly-Linked List in Java, 2

© 2014 Goodrich, Tamassia, Goldwasser Doubly Linked Lists 6

Page 4: Doubly Linked Lists - Lehman Collegecomet.lehman.cuny.edu › sfakhouri › teaching › cmp › cmp338... · Doubly Linked Lists 3/18/14 2 Doubly Linked Lists 3 Insertion ! Insert

Doubly Linked Lists 3/18/14

4

Doubly-Linked List in Java, 3

© 2014 Goodrich, Tamassia, Goldwasser Doubly Linked Lists 7

Doubly-Linked List in Java, 4

© 2014 Goodrich, Tamassia, Goldwasser Doubly Linked Lists 8