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.

Slides:



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

Lists A list is a finite, ordered sequence of data items. Important concept: List elements have a position. Notation: What operations should we implement?
Chapter 24 Lists, Stacks, and Queues
Linked Lists Linear collections.
© 2004 Goodrich, Tamassia Node-Lists1 6.2 Node Lists.
Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
AITI Lecture 19 Linked List Adapted from MIT Course 1.00 Spring 2003 Lecture 26 and Tutorial Note 9 (Teachers: Please do not erase the above note)
Double-Linked Lists and Circular Lists
The List ADT Textbook Sections
CSC 212 – Data Structures Lecture 22: PositionList.
Iterators and Sequences1 © 2010 Goodrich, Tamassia.
© 2004 Goodrich, Tamassia Vectors1. © 2004 Goodrich, Tamassia Vectors2 The Vector ADT (“Vector” = “Array List” in §6.1) The Vector ADT extends the notion.
© 2004 Goodrich, Tamassia Sequences and Iterators1.
Queues 4/14/2017 5:24 PM 5.2 Queues Queues Dr Zeinab Eid.
CSC 212 – Data Structures. Using Stack Stack Limitations  Great for Pez dispensers, JVMs,& methods  All of these use most recent item added only 
CSC 212 – Data Structures.  Fri., Dec. 17 th from 8AM – 10AM in OM 200  Plan on exam taking full 2 hours  If major problem, come talk to me ASAP 
Problem of the Day  What do you get when you cross a mountain climber and a grape?
Problem of the Day  At low tide, a ship docks in the harbor  Ship is 9’ above the water line when it docks  Over the side hangs a rope ladder w/ rungs.
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.
CSE 143 Lecture 22: Advanced List Implementation (ADTs; interfaces; abstract classes; inner classes; generics; iterators)
Lists and Iterators CSC311: Data Structures 1 Chapter 6 Lists and Iterators Objectives Array Lists and Vectors: ADT and Implementation Node Lists: ADT.
Lists and Iterators (Chapter 6) COMP53 Oct 22, 2007.
CSC 212 Vectors, Lists, & Sequences. Announcement Daily quizzes accepted electronically only  Submit via one or other Dropbox  also accepted,
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Fall 2007CS 2251 Lists and the Collection Interface Chapter 4.
CSC 212 Stacks & Queues. Announcement Daily quizzes accepted electronically only  Submit via one or other Dropbox  Cannot force you to compile & test.
CSC 212 – Data Structures Lecture 21: IndexList a/k/a Vector, ArrayList.
Problem Of The Day  Decipher the following phrase: STANDS 0 _
CSC 212 – Data Structures Lecture 20: Deques. Question of the Day How did the clerk know that the man telling the following story is a fraud? I hope you.
Problem of the Day  Rich old man tells his 2 children he will hold a race to decide who gets his fortune. SLOWEST  Winner is one who owns SLOWEST horse.
Problem of the Day  What do you get when you cross a mountain climber and a grape?
Problem of the Day  What do you get when you cross a mountain climber and a grape?
Problem of the Day  At low tide, a ship docks in the harbor  Ship is 9’ above the water line when it docks  Over the side hangs a rope ladder w/ rungs.
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,
CSC 212 Stacks & Queues. Announcement Many programs not compiled before submission  Several could not be compiled  Several others not tested with javadoc.
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.
LinkedList Many slides from Horstmann modified by Dr V.
LECTURE 26: QUEUES CSC 212 – Data Structures. Using Stack.
LECTURE 34: MAPS & HASH CSC 212 – Data Structures.
CSC 212 – Data Structures Lecture 37: Course Review.
CSC 212 – Data Structures.  Fri., Dec. 14 th from 2:45 – 4:45PM in SH1028  Plan on exam taking full 2 hours  If major problem, come talk to me ASAP.
4-1 Topic 6 Linked Data Structures. 4-2 Objectives Describe linked structures Compare linked structures to array- based structures Explore the techniques.
CSE 143 Lecture 24 Advanced collection classes (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, , slides.
CSC 212 – Data Structures Lecture 26: Hash Tables.
Problem of the Day  Simplify this equation: (x - a) * (x - b) * (x - c) * … * (x - z)
Question of the Day  Two English words change their pronunciation when their first letter is capitalized. What are they?
Question of the Day  Three people check into a hotel for which they pay the manager $30. The manager finds out the rate is $25 and gives $5 to the bellboy.
LECTURE 27: DEQUES CSC 212 – Data Structures. Roses are red and violets are blue Implement push, pop, & top And you’re a Stack too! Stack & ADT Memory.
COMP 121 Week 11: Linked Lists.
Ordered Linked Lists using Abstract Data Types (ADT) in Java Presented by: Andrew Aken.
Lecture Objectives  Linked list data structures:  Singly-linked (cont.)  Doubly-linked  Circular  Implementing the List interface as a linked list.
1 CMPSCI 187 Computer Science 187 Introduction to Introduction to Programming with Data Structures Lecture 8 Lists, Iterators, and Doubly Linked Lists.
CSC 212 – Data Structures Lecture 23: Iterators. Question of the Day Thieves guild states it will sell to members: lock picking kits  $0.67 each 40’
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  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 – Data Structures.  Tues., Dec. 10 th from 8:00 – 10:ooAM in OM220  Plan on exam taking full 2 hours  If major problem, come talk to me ASAP.
1 Stacks (Continued) and Queues Array Stack Implementation Linked Stack Implementation The java.util.Stack class Queue Abstract Data Type (ADT) Queue ADT.
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,
List Interface and Linked List Mrs. Furman March 25, 2010.
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.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 18 List ADT Animated Version.
Question of the Day  What three letter word completes the first word and starts the second one: DON???CAR.
Problem of the Day  Simplify this equation: (x - a) * (x - b) * (x - c) * … * (x - z)
CSCI 62 Data Structures Dr. Joshua Stough September 23, 2008.
The List ADT.
Ch7. List and Iterator ADTs
Sequences and Iterators
Lecture 23: Doubly Linked List
Lecture No.02 Data Structures Dr. Sohail Aslam
Presentation transcript:

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 1,317 miles apart, how far apart are they 1 minute before colliding?

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 1,317 miles apart, how far apart are they 1 minute before colliding? They are closing at 30,000MPH ; 1 minute of this is: 30,000/60 = 3000/6 = 500 miles!

CSC 212 – Data Structures

I NDEX L IST ≠ array  Extends array concepts, like using indices, but…  I NDEX L IST s do not have constant size  Element’s index changes as data added & removed  ADTs remain completely implementation-free  Using non-tenured faculty still perfectly acceptable

I NDEX L IST.add()  add( i, e ) “shifts” elements to make space  Traverse linked list or move array elements  Can take O(n) time for this shifting  Worst case occurs in both array- & linked list-based  May only take O(1) to add to end of list 012 e n-1 i

I NDEX L IST.remove()  remove( i ) “shifts” elements down to fill hole  Not implementation-specific – only indices are shifted  O(n) time required in the general case  But for specific situations could take only O(1) time  But must consider worst case when computing big-Oh 012 e n-1 i

I NDEX L IST D EQUE Q UEUE S TACK add() addFront() addLast() enqueue()push() get() getFront() getLast() front()top() remove () removeFront() removeLast() dequeue()pop() set() None! Operations To Date

 Collection which we can access all elements  Add element before an existing one  Return the Collection’s 3 rd element  Loop over all elements without removing them  L IST ADTs differ in how they provide access  I NDEX L IST uses indices for absolution positioning  Can only use relative positions in N ODE L IST List ADT

Does Absolute Position Matter?

Relativity Can Be Important

 Based upon a conceptual linked list  No implementation specified  No implementation specified: still an ADT  Relies upon Node s implementing P OSITION ADT  P OSITION s at relative locations in the L IST  first() & last() P OSITION s only absolutes  Traverse using next(p) & prev(p) methods P OSITION L IST with 3 elements N ODE L IST ADT first last

 Abstracts Node idea for use anywhere  Get the P OSITION 's value using element()  Cannot change element using interface's methods  Position is ADT & works with array elements class ArrayPos implements Position { private E[] theArray; private int index; public ArrayPos(E[] arr, int idx) { … } public E element(){ return theArray[index]; } } P OSITION Interface

public interface PositionList extends Collection { Position first(); Position last(); Position next(Position p) throws /* … */ ; Position prev(Position p) throws /* … */ ; E set(Position p, E elem) throws /* … */ ; E remove(Position p) throws /* … */ ; void addFirst(E elem); void addLast(E elem); void addBefore(Position p, E e) throws /*…*/ ; void addAfter(Position p, E e) throws /* …*/ ; } Memorization Limits

 Good news: remove & set the same  Now take P OSITION as parameter and not an index  Whatever it had as its value before call returned  Relative location used to add elements to L IST  addFirst & addLast are relative to all others  e in new P OSITION before p via addBefore  addNext creates new P OSITION after p for e N ODE L IST Methods

 Linked list implements N ODE L IST in most cases  This is not required, but is most reasonable  Few methods free with doubly-linked lists  Use next & prev fields to move between P OSITION s  Call Node. setElement(e) to implement set  Most other methods we've already implemented  Just adding & removing Node s from the linked list Implementing N ODE L IST

 Linked list implements N ODE L IST in most cases  This is not required, but is most reasonable  Few methods free with doubly-linked lists  Use next & prev fields to move between P OSITION s  Call Node. setElement(e) to implement set  Most other methods we've already implemented  Just adding & removing Node s from the linked list But how to do this with P OSITION s? Implementing N ODE L IST

Typecasting Explained

 Used when we implement PositionList  Class allocates instance, so typecasting is safe private Node checkPosition(Position p) throws InvalidPositionException { if ((p == null) || !(p instanceof Node)) { throw new InvalidPositionException(); } return (Node )p; } From Position to Node

Your Turn  Get into your groups and complete activity

For Next Lecture  Before Wednesday’s lecture read GT 6.3  What is an Iterator ? How is it used?  How are Iterable classes related to List s?  Are Iterable & Iterator s related? If so, how?  Programming Assignment #2  Programming Assignment #2 available now good  javadoc is your friend; please write good comments