CS 228 meeting -*- Outline -*- * introduction to linked lists (HR 8.1) This chapter studies the *implementation* data structure of linked lists. We'll use it to implement the ADT List. ** overview one way to think of this is... Q: what would we have to do to implement something like Scheme? ------------------------------------------ HR CHAPTER 8 LISTS AND LINKED LISTS Topics: A. pointers and structs B. dynamic data implementation 1. head nodes 2. doubly linked lists 3. circular lists C. Array implementation 1. managing the free store (heap) ------------------------------------------ ** motivation ------------------------------------------ THE PROBLEM Linear, homogeneous, ordered collection. Often inserting and taking items out of from random spots in the collection. ------------------------------------------ Like implementing the List ADT Examples: storing guest list at a hotel Q: What's the problem with using an array for this? have to shift when insert or delete. draw picture, note the inefficiency Q: What's the big-O complexity of using an array for each insertion? O(n) would like it to be linear! (write that on the slide). What's the complexit of using the flexible arrays? O(n), as still have shifting going on. ** singly-linked lists ------------------------------------------ SINGLY-LINKED LISTS PICTURES AND TERMINOLOGY Typical singly-linked list: Inserting after first element: Splicing out third element: def: A *singly-linked list* consists of a collection of ________ called ________, each containing a ______________________, and some data. ------------------------------------------ ... structs called nodes ... link (which is a pointer)