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 25 Lists, Stacks, Queues, and Priority Queues
Advertisements

Chapter 22 Implementing lists: linked implementations.
1 Linked Lists Continued Lecture 5 Copying and sorting singly linked lists Lists with head and last nodes Doubly linked lists ADS2 Lecture 5.
Singly linked lists Doubly linked lists
© 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
Chapter 24 Lists, Stacks, and Queues
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.
Data Structure Lecture-5
David Weinberg presents Linked Lists: The Background  Linked Lists are similar to ArrayLists in their appearance and method of manipulation  They do.
Queues A waiting line that grows by adding elements to its end and shrinks by taking elements from its front Line at the grocery store Cars in traffic.
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
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.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 17: Linked Lists.
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.
1 Data Structures Data Structures Topic #2. 2 Today’s Agenda Data Abstraction –Given what we talked about last time, we need to step through an example.
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.
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.
Problem of the Day Bezout acquired 19 camels through his trading skill, “Of the collected camels,” it said in the late merchant’s will, “Exactly half go.
4-1 Topic 6 Linked Data Structures. 4-2 Objectives Describe linked structures Compare linked structures to array- based structures Explore the techniques.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 17: Linked Lists.
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?
Linked List by Chapter 5 Linked List by
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
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.
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,
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
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”
Question of the Day  What three letter word completes the first word and starts the second one: DON???CAR.
 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.
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.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Lists List Implementations. 2 Linked List Review Recall from CMSC 201 –“A linked list is a linear collection of self- referential structures, called nodes,
Arrays, Link Lists, and Recursion Chapter 3. Sorting Arrays: Insertion Sort Insertion Sort: Insertion sort is an elementary sorting algorithm that sorts.
CC 215 DATA STRUCTURES LINKED LISTS Dr. Manal Helal - Fall 2014 Lecture 3 AASTMT Engineering and Technology College 1.
Lecture 6 of Computer Science II
Linked List Stacks, Linked List Queues, Dequeues
EEL 4854 IT Data Structures Linked Lists
Linked Lists.
CS212D: Data Structures Week 5-6 Linked List.
Header and Trailer Sentinels
Lecture No.02 Data Structures Dr. Sohail Aslam
BY PROF. IRSHAD AHMAD LONE.
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

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()

SLinkedList head size  4 SLinkedList head size  3

T removeMiddle(Node prev) SLinkedList head size  4 SLinkedList 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) SLinkedList head size  4 SLinkedList 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 & Sentinels 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 & Sentinels Doubly Linked List With 4 Elements & Sentinels DList head tail size  4 Ø Ø

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 BCD head A

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 #7 weekly assignment available now  Angel also has programming assignment #1  Pulls everything together and shows off your stuff