Question of the Day A friend tells the truth when saying: A road near my house runs directly north-south; I get on the road facing north, drive for a mile,

Slides:



Advertisements
Similar presentations
Chapter 22 Implementing lists: linked implementations.
Advertisements

1 Linked Lists Continued Lecture 5 Copying and sorting singly linked lists Lists with head and last nodes Doubly linked lists ADS2 Lecture 5.
© 2004 Goodrich, Tamassia Linked Lists1. © 2004 Goodrich, Tamassia Linked Lists2 Arrays: pluses and minuses + Fast element access. -- Impossible to resize.
CS 367 – Introduction to Data Structures
Data Structures ADT List
Chapter 24 Lists, Stacks, and Queues
Linked Lists Linked Lists Representation Traversing a Linked List
Chapter 3 – Lists A list is just what the name implies, a finite, ordered sequence of items. Order indicates each item has a position. A list of size 0.
CHP-5 LinkedList.
Chapter 17 Linked List Saurav Karmakar Spring 2007.
3 May Linked Lists CSE 2011 Winter Linked Lists2 Singly Linked Lists (3.2) A singly linked list is a concrete data structure consisting of.
Review Learn about linked lists
Iterators and Sequences1 © 2010 Goodrich, Tamassia.
Doubly Linked Lists. One powerful variation of a linked list is the doubly linked list. The doubly linked list structure is one in which each node has.
CSC 212 – Data Structures. Using Stack Stack Limitations  Great for Pez dispensers, JVMs,& methods  All of these use most recent item added only 
Problem of the Day  What do you get when you cross a mountain climber and a grape?
Lecture 8 CS203. Implementation of Data Structures 2 In the last couple of weeks, we have covered various data structures that are implemented in the.
1 Chapter 24 Lists Stacks and Queues. 2 Objectives F To design list with interface and abstract class (§24.2). F To design and implement a dynamic list.
CS 206 Introduction to Computer Science II 09 / 17 / 2008 Instructor: Michael Eckmann.
Linked Lists. Example We would like to keep a list of inventory records – but only as many as we need An array is a fixed size Instead – use a linked.
Main Index Contents 11 Main Index Contents Abstract Model of a List Obj. Abstract Model of a List Obj. Insertion into a List Insertion into a List Linked.
Data Structures Topic #3. Today’s Agenda Ordered List ADTs –What are they –Discuss two different interpretations of an “ordered list” –Are manipulated.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 17 Linked.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 26 Implementing Lists, Stacks,
Chapter 3: Arrays, Linked Lists, and Recursion
CSC 212 – Data Structures Lecture 13: Linked Lists.
Fall 2006CSC311: Data Structures1 Chapter 3 Arrays, Linked Lists, and Recursion Objectives –Using Arrays –Singly Linked Lists –Doubly Linked Lists –Circularly.
CS 206 Introduction to Computer Science II 09 / 19 / 2008 Instructor: Michael Eckmann.
Arrays & Linked Lists Last Update: Aug 21, 2014EECS2011: Arrays & Linked Lists1.
Question of the Day A friend tells the truth when saying: A road near my house runs directly north-south; I get on the road facing north, drive for a mile,
1 Linked Lists (continued (continued)) Lecture 5 (maybe) Copying and sorting singly linked lists Lists with head and last nodes Doubly linked lists Append/Circular.
CSE 131 Computer Science 1 Module 9: Linked Lists Using references to link objects Basic operations on linked lists Implementing a linked list of integers.
Problem of the Day  What do you get when you cross a mountain climber and a grape?
CS212D : DATA STRUCTURES 1 Week 5-6 Linked List. Outline 2  Singly Linked Lists  Doubly Linked Lists  Recursions.
Question of the Day A friend tells the truth when saying: A road near my house runs directly north-south; I get on the road facing north, drive for a mile,
Data Structures Using Java1 Chapter 4 Linked Lists.
4-1 Topic 6 Linked Data Structures. 4-2 Objectives Describe linked structures Compare linked structures to array- based structures Explore the techniques.
A Doubly Linked List prevnextdata There’s the need to access a list in reverse order header dnode.
Kovács Zita 2014/2015. II. félév DATA STRUCTURES AND ALGORITHMS 26 February 2015, Linked list.
Question of the Day  Two English words change their pronunciation when their first letter is capitalized. What are they?
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
Problem Of The Day  Two missiles speed directly toward each other  One goes 9,000 miles per hour  Other goes 21,000 miles per hour.  If they start.
Subject Name : Data Structure Using C Title : Linked Lists
Data Structures Using C++1 Chapter 5 Linked Lists.
Question of the Day  How can you change the position of 1 toothpick and leave the giraffe in exactly the same form, but possibly mirror-imaged or oriented.
CSC 212 Sequences & Iterators. Announcements Midterm in one week  Will cover through chapter 5 of book  Midterm will be open book, open note (but, closed.
List Interface and Linked List Mrs. Furman March 25, 2010.
Data Structures Doubly and Circular Lists Lecture 07: Linked Lists
Introduction Dynamic Data Structures Grow and shrink at execution time Linked lists are dynamic structures where data items are “linked up in a chain”
 Array is a data structure were elements are stored in consecutive memory location.in the array once the memory is allocated.it cannot be extend any more.
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
Question of the Day  How can you change the position of 1 toothpick and leave the giraffe in exactly the same form, but possibly mirror-imaged or oriented.
LECTURE 21: RECURSION & LINKED LIST REVIEW CSC 212 – Data Structures.
Question of the Day  What three letter word completes the first word and starts the second one: DON???CAR.
CSCS-200 Data Structure and Algorithms Lecture
Doubly Linked List Exercises Sometimes it is useful to have a linked list with pointers to both the next and previous nodes. This is called a doubly linked.
Arrays, Link Lists, and Recursion Chapter 3. Sorting Arrays: Insertion Sort Insertion Sort: Insertion sort is an elementary sorting algorithm that sorts.
LINKED LISTS.
Lecture 6 of Computer Science II
Linked List Stacks, Linked List Queues, Dequeues
EEL 4854 IT Data Structures Linked Lists
Linked Lists.
[Chapter 4; Chapter 6, pp ] CSC 143 Linked Lists [Chapter 4; Chapter 6, pp ]
Doubly Linked Lists or Two-way Linked Lists
CS212D: Data Structures Week 5-6 Linked List.
Header and Trailer Sentinels
Lecture No.02 Data Structures Dr. Sohail Aslam
CS210- Lecture 6 Jun 13, 2005 Announcements
Chapter 9 Linked Lists.
Jyh-Shing Roger Jang (張智星) CSIE Dept, National Taiwan University
Presentation transcript:

Question of the Day A friend tells the truth when saying: A road near my house runs directly north-south; I get on the road facing north, drive for a mile, & end up south of where I started How does he do it?

Question of the Day A friend tells the truth when saying: A road near my house runs directly north-south; I get on the road facing north, drive for a mile, & end up south of where I started How does he do it? Note: He (anyone) doesn't live near the north pole

Question of the Day

 Are created using linear sequence of nodes  Each Node contains:  Reference to data (element) stored in Node  Link to next Node in linked list Singly Linked List elemnextelemnextelemnextelemnext Node head size  4 SLinkedList

Node s Are Not Enough  Node s are workers making linked lists possible  Necessary for the smooth running of linked list  Treated like other jobs smoothing things out  Added & removed as needed  Used only to keep the list running

Node s Are Not Enough

 Node s are workers making linked lists possible  Necessary for the smooth running of linked list  Treated like other jobs smoothing things out  Added & removed as needed  Used only to keep the list running  Never allowed outside of the linked list

Node s Are Not Enough

T removeFirst()

head size  4 head size  3

T removeMiddle(Node prev) head size  4 head size  3

Traversing a List  Often need to go through items in a list  Return element stored by the n th Node  Search and find if element is in list  Count elements larger/smaller/equal than some value  Add an element at list’s end  Cannot do this directly with linked lists  Arrays have brackets, but linked lists use objects  Must traverse list by travelling from Node to Node  Relies heavily on understanding how objects work

void addLast(T el) head size  4 head size  5

 Link to previous node in list also in each node  Each DNode contains:  Element (data) reference  Link to next DNode  Prev(ious) DNode also linked Doubly Linked List elem DNode Instance nextprev

 Link to previous node in list also in each node  Each DNode contains:  Element (data) reference  Link to next DNode  Prev(ious) DNode also linked Doubly Linked List Doubly Linked List With 4 Elements

 Link to previous node in list also in each node  Each DNode contains:  Element (data) reference  Link to next DNode  Prev(ious) DNode also linked Doubly Linked List Sequence of 4 DNode s

 Link to previous node in list also in each node  Each DNode contains:  Element (data) reference  Link to next DNode  Prev(ious) DNode also linked Doubly Linked List Doubly Linked List With 4 Elements & Sentinels

 Link to previous node in list also in each node  Each DNode contains:  Element (data) reference  Link to next DNode  Prev(ious) DNode also linked Doubly Linked List Doubly Linked List With 4 Elements & Sentinels header trailer size  4 DList

Doubly Linked List  DNode could extend Node  next & elem fields are needed by both classes  Only difference is prev field added by DNode  DList is not subclass of SList  Both classes define identical methods…  …are entirely different when implemented

 Identical nodes as singly or doubly linked list  This example shows singly linked variety  Reference to first node stored in last node  Notice this becomes a big circle  Now you know idea behind name Circular Linked List head size  4

Your Turn  Get into your groups and complete activity

For Next Lecture  Read GT3.5 for Wednesday  What is recursion?  Why does recursion rock so much?  How do you write a recursive method?  Week #6 weekly assignment available now  Since no school Tues., assignment due Wednesday  Programming assignment #1 delayed until Wed.  If you all agree, project would be much cooler & fun  Pulls everything together & sees how much you know