Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 206 Introduction to Computer Science II 09 / 19 / 2008 Instructor: Michael Eckmann.

Similar presentations


Presentation on theme: "CS 206 Introduction to Computer Science II 09 / 19 / 2008 Instructor: Michael Eckmann."— Presentation transcript:

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

2 Michael Eckmann - Skidmore College - CS 206 - Fall 2008 Today’s Topics Questions? Comments? Linked lists –Singly linked lists with addition of a tail –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.)‏ 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


Download ppt "CS 206 Introduction to Computer Science II 09 / 19 / 2008 Instructor: Michael Eckmann."

Similar presentations


Ads by Google