Announcements & Review

Slides:



Advertisements
Similar presentations
The List ADT Textbook Sections
Advertisements

CSC 205 – Java Programming II Lecture 25 March 8, 2002.
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.
CSE 143 Lecture 22: Advanced List Implementation (ADTs; interfaces; abstract classes; inner classes; generics; iterators)
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L11 (Chapter 20) Lists, Stacks,
CS 307 Fundamentals of Computer Science 1 Lists and ArrayList many slides taken from Mike Scott, UT Austin.
24-Jun-15 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Lists in Java Part of the Collections Framework. Kinds of Collections Collection --a group of objects, called elements –Set-- An unordered collection.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 26 Implementing Lists, Stacks,
CSC 212 – Data Structures Lecture 21: IndexList a/k/a Vector, ArrayList.
Linked Lists. RHS – SOC 2 Linked lists We can already store collec- tions of objects in arrays and array lists – why would we need other data structures…?
Collections in Java. Kinds of Collections Collection --a group of objects, called elements –Set-- An unordered collection with no duplicates SortedSet.
CSC 142 J(part 1) 1 CSC 142 The ArrayList class [Reading: chapter 10]
LinkedList Many slides from Horstmann modified by Dr V.
1 Chapter 17 Object-Oriented Data Structures. 2 Objectives F To describe what a data structure is (§17.1). F To explain the limitations of arrays (§17.1).
1/20/03A2-1 CS494 Interfaces and Collection in Java.
Collections in Java. 2 Collections Hierarchy > ArrayListVector Stack LinkedList > Arrays Collections.
CS-2852 Data Structures LECTURE 7A Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
Linked Lists Ellen Walker CPSC 201 Data Structures Hiram College.
3-February-2003cse Collections © 2003 University of Washington1 Java Collections CSE 403, Winter 2003 Software Engineering
ArrayList By Neil Butcher. What is the difference between an ArrayList and an Array? An ArrayList is in many ways similar to an array, but has a few subtle.
CSS446 Spring 2014 Nan Wang.  To understand the implementation of linked lists and array lists  To analyze the efficiency of fundamental operations.
Collections Mrs. C. Furman April 21, Collection Classes ArrayList and LinkedList implements List HashSet implements Set TreeSet implements SortedSet.
1 TCSS 342, Winter 2005 Lecture Notes Linked List Implementation Weiss Ch. 6, pp Weiss Ch. 17, pp
© 2006 Pearson Addison-Wesley. All rights reserved5 B-1 Chapter 5 (continued) Linked Lists.
List Interface and Linked List Mrs. Furman March 25, 2010.
Recursive Objects (Part 2) 1. Adding to the front of the list  adding to the front of the list  t.addFirst('z') or t.add(0, 'z') 2 'a' 'x' LinkedList.
Data Structures I Collection, List, ArrayList, LinkedList, Iterator, ListNode.
1 CMPSCI 187 Computer Science 187 Introduction to Introduction to Programming with Data Structures Lecture 9 Doubly Linked Lists and Ordered Lists Lecture.
Recursive Objects Singly Linked List (Part 2) 1. Operations at the head of the list  operations at the head of the list require special handling because.
1 Chapter 24 Implementing Lists, Stacks, Queues, and Priority Queues Jung Soo (Sue) Lim Cal State LA.
Java Collections CHAPTER 3-February-2003
CSCI 62 Data Structures Dr. Joshua Stough September 23, 2008.
An Array-Based Implementation of the ADT List
Single-Linked Lists.
The List ADT Reading: Textbook Sections 3.1 – 3.5
Marcus Biel, Software Craftsman
Linked Lists Chapter 5 (continued)
Data Structures Lakshmish Ramaswamy.
COP 3503 FALL 2012 Shayan Javed Lecture 8
Java collections library
Chapter 17 Object-Oriented Data Structures
Heaps & Priority Queues
Linked Lists.
Object Oriented Programming COP3330 / CGS5409
Programming in Java Lecture 11: ArrayList
Linked List Intro CSCE 121 J. Michael Moore.
The List ADT Reading: Textbook Sections 3.1 – 3.5
CSE 143 Lecture 27: Advanced List Implementation
Lecture 26: Advanced List Implementation
Arrays versus ArrayList
ArrayList Collections.
Programming II (CS300) Chapter 07: Linked Lists and Iterators
Chapter 24 Implementing Lists, Stacks, Queues, and Priority Queues
Building Java Programs
Collections Framework
JCF Collection classes and interfaces
Programming II (CS300) Chapter 02: Using Objects Java ArrayList Class
Linked Lists Chapter 5 (continued)
CS210- Lecture 6 Jun 13, 2005 Announcements
Programming II (CS300) Chapter 07: Linked Lists
Linked List Intro CSCE 121.
Iterators Dan Fleck.
TCSS 143, Autumn 2004 Lecture Notes
CSE 143 Lecture 21 Advanced List Implementation
Linked Lists Chapter 5 (continued)
Java Generics & Iterators
Problem Understanding
Presentation transcript:

Announcements & Review Last Time: Collections ArrayList - look up - constant time remove, resizing, insert in the middle - expensive, time proportional to the list size Today: a new collection Linked List - similar operations as ArrayList, but different storage model resizing, removal, insertion - constant time find - proportional to list size. Announcements Lab 9: Inheritance Defining & using class hiearchies Read: R&S 11 Lecture 30: Collections Linked List

Linked List Storage Model start end null next Key: prev node No diriect indexing, as in arrays, so you must iterate over the list to enumerate an element Adding at the front or the back is constant time, i.e., resizing is cheap Lecture 30: Collections Linked List

Interesting LinkedList<E> Methods size() - returns number of objects add(Object o) - adds at end of list get(int i) - returns ith object in the list set(int i, Object o) - stores o at ith position in list add(int i, Object o) - adds o at ith position, shifts other objects to the right E remove() - removes and returns element current position, shifts elements to the left removeFirst(), removeLast(), remove(E v), remove(int i), remove() Lecture 30: Collections Linked List

Interesting LinkedList<E> Methods E clone() - return a shallow copy of the list Boolean addAll(LinkedList<E> c) - add collection c to end of list, return true if list changes E peek() - return the first element without removing it from the list Boolean hasNext(), E next() - iteration Lecture 30: Collections Linked List

Lecture 30: Collections Linked List apples null 33 41 8 101 14 McIntosh Red Gala Fuji Golden Delicious Linked list example declaration (same as ArrayList): LinkedList<Items> apples = new LinkedList<Items>(); Items a = new Items(“McIntosh”, 33); apples.add(a); a = new Items(“Red”, 41); apples.add(a); ... Lecture 30: Collections Linked List

Iterators for LinkedList // Basic format: Iterator<E> itr = list.iterator(); while (itr.hasNext()) { E element = itr.next(); // do something with the object } // Example: Delete “Gala” apples inventory LinkedList<Items> apples = new LinkedList<Items>(); ... Iterator<Items> i = apples.iterator(); while (i.hasNext()) { Items item = i.next(); if (item.getName().equals(“Gala”)) { i.remove(); } } Lecture 30: Collections Linked List

Lecture 30: Collections Linked List BlueJ Lecture 30: Collections Linked List