Download presentation

Presentation is loading. Please wait.

1
CS 206 Introduction to Computer Science II 09 / 17 / 2008 Instructor: Michael Eckmann

2
Michael Eckmann - Skidmore College - CS 206 - Fall 2008 Today’s Topics Questions? Comments? Linked lists –Finish the delete a node code from last time –Change the Deck class to store a linked list of CardNodes instead of an ArrayList of Cards. –Doubly linked lists

3
Linked lists A linked list is a data structure where every node contains data and reference(s) to other node(s.) Let's look at drawings on the board. Let's figure out how to – Add to beginning of linked list – Add to end of linked list Need to find last node – Insert after a particular node – Delete a particular node Other options – Storing link to last node – Doubly linked lists (and their operations.) – Circular linked lists (where the “last” node refers to the “head”).

4
Linked lists What's deficient in singly linked lists?

5
Linked lists What's deficient in singly linked lists? –can't add to the end of the list efficiently (add tail) what gets easier? How to do it; what needs to change? –can't “back up” if necessary, so we can't say, traverse the linked list from the tail to the head because we only have a next (one way) create a doubly linked list = add links that go both ways (next and prev)

6
Linked lists A doubly linked list is a data structure where every node contains – data – a reference to previous node – a reference to next node The value of the next node for the last element of a linked list is null. The value of the previous node for the first element of a linked list is also null.

7
Linked lists Let's consider operations for a doubly linked list on the board. A doubly linked list is a data structure where every node has – data – a reference to previous node (prev) – a reference to next node (next) We maintain a head node and a tail node. The value of the next node for the last (tail) element of a linked list is null. The value of the previous node for the first (head) element of a linked list is also null. When you construct a new node, set the data and next and prev default to null

Similar presentations

© 2020 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google