Chapter 5 Linked Lists © 2011 Pearson Addison-Wesley. All rights reserved.

Slides:



Advertisements
Similar presentations
Inserting a Node into a Specified Position of a Linked List To create a node for the new item newNode = new Node(item); To insert a node between two nodes.
Advertisements

Chapter 4 Linked Lists. © 2005 Pearson Addison-Wesley. All rights reserved4-2 Preliminaries Options for implementing an ADT List –Array has a fixed size.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 4: Linked Lists Data Abstraction & Problem Solving with.
© 2006 Pearson Addison-Wesley. All rights reserved5 A-1 Chapter 5 Linked Lists CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2008.
An Array-Based Implementation of the ADT List public class ListArrayBased implements ListInterface { private static final int MAX_LIST = 50; private Object.
1 Chapter 3 Arrays, Linked Lists, and Recursion. 2 Static vs. Dynamic Structures A static data structure has a fixed size This meaning is different than.
Linked Lists. Preliminaries Options for implementing an ADT List Array Has a fixed size Data must be shifted during insertions and deletions Dynamic array.
CMPT 225 ADT List using Dynamic arrays A dynamic data structure is one that changes size, as needed, as items are inserted or removed The Java ArrayList.
© 2006 Pearson Addison-Wesley. All rights reserved5 A-1 Chapter 5 Linked Lists.
Chapter 4 Linked Lists. © 2005 Pearson Addison-Wesley. All rights reserved4-2 Preliminaries Options for implementing an ADT List –Array has a fixed size.
Chapter 4 Linked Lists. © 2005 Pearson Addison-Wesley. All rights reserved4-2 Preliminaries Options for implementing an ADT List –Array has a fixed size.
2 Preliminaries Options for implementing an ADT List Array has a fixed size Data must be shifted during insertions and deletions Linked list is able to.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 4: Linked Lists Data Abstraction & Problem Solving with.
Dynamic Array. An Array-Based Implementation - Summary Good things:  Fast, random access of elements  Very memory efficient, very little memory is required.
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
© 2006 Pearson Addison-Wesley. All rights reserved5 B-1 Chapter 5 (continued) Linked Lists.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
Linked Lists Chapter 4. Linked Structures: Motivations Arrays have fixed size –Problematic for data structures of arbitrary size Arrays order items physically.
Chapter 5 Linked Lists. © 2004 Pearson Addison-Wesley. All rights reserved 5 A-2 Preliminaries Options for implementing an ADT –Array Has a fixed size.
Data Abstraction and Problem Solving with C++ Walls and Mirrors, Third Edition, Frank M. Carrano and Janet J. Prichard ©2002 Addison Wesley CHAPTER 4 Linked.
CC 215 DATA STRUCTURES LINKED LISTS Dr. Manal Helal - Fall 2014 Lecture 3 AASTMT Engineering and Technology College 1.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
An Array-Based Implementation of the ADT List
Data Abstraction: The Walls
Chapter 4 Linked Structures.
Trees Chapter 11 (continued)
Chapter 5 Linked Lists © 2006 Pearson Addison-Wesley. All rights reserved.
Linked Lists Chapter 5 (continued)
Linked Lists Chapter 6 Section 6.4 – 6.6
Trees Chapter 11 (continued)
Chapter 5 Linked Lists © 2011 Pearson Addison-Wesley. All rights reserved.
Intro To Classes Review
Chapter 4 Linked Lists.
Bag Implementations that Use Arrays
Chapter 4 Linked Lists
A Bag Implementation that Links Data
Array Lists Chapter 6 Section 6.1 to 6.3
Chapter 17 Linked Lists.
Chapter 19 Binary Search Trees.
Algorithm Efficiency and Sorting
Chapter 4 Inheritance.
Chapter 4 Linked Lists.
Chapter 14 Graphs and Paths.
Chapter 12 Collections.
Foundational Data Structures
List Implementations Chapter 9.
Chapter 10 Datapath Subsystems.
Chapter 5 Linked Lists © 2006 Pearson Addison-Wesley. All rights reserved.
Object Oriented Programming in java
Chapter 20 Hash Tables.
Indirection.
Linked Lists Chapter 4.
Chapter 4 Linked Lists.
Linked Lists The items in a linked list data structure are linked to one another An item in a linked list references its successor A linked list is able.
Figure 4.1 a) A linked list of integers; b) insertion; c) deletion.
Chapter 12 Collections.
The Facts to Be Explained
Linked Lists Chapter 5 (continued)
C H A P T E R F I V E Memory Management.
Chapter 5 Linked Lists © 2006 Pearson Addison-Wesley. All rights reserved.
Queues cont. Chapter 8 © 2011 Pearson Addison-Wesley. All rights reserved.
Chapter 12 Heap ADT © 2011 Pearson Addison-Wesley. All rights reserved.
Circuit Characterization and Performance Estimation
Classes and Objects Object Creation
Linked Lists Chapter 5 (continued)
Chapter 2 Reference Types.
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
Linked Lists Chapter 5 (continued)
CMSC 202 Constructors Version 9/10.
A List Implementation that Uses An Array
Presentation transcript:

Chapter 5 Linked Lists © 2011 Pearson Addison-Wesley. All rights reserved

Preliminaries Options for implementing an ADT Array Has a fixed size Data must be shifted during insertions and deletions ArrayList and Linked List Is able to grow in size as needed © 2011 Pearson Addison-Wesley. All rights reserved

Object References A reference variable Contains the location of an object Example Integer intRef = new Integer(5); As a data field of a class Has the default value null © 2011 Pearson Addison-Wesley. All rights reserved

Object References When one reference variable is assigned to another reference variable, both references then refer to the same object Integer p, q; p = new Integer(6); q = p; A reference variable that no longer references any object is marked for garbage collection © 2011 Pearson Addison-Wesley. All rights reserved

Object References Figure 5-3a-d a) Declaring reference variables; b) allocating an object; c) allocating another object, with the dereferenced object marked for garbage collection © 2011 Pearson Addison-Wesley. All rights reserved

Object References Equality operators (== and !=) equals method Compare the values of the reference variables, not the objects that they reference equals method Compares objects field by field When an object is passed to a method as an argument, the reference to the object is copied to the method’s formal parameter Reference-based ADT implementations and data structures use Java references © 2011 Pearson Addison-Wesley. All rights reserved

Resizable Arrays The number of references in a Java array is of fixed size Resizable array (ArrayList) An array that grows and shrinks as the program executes An illusion that is created by using an allocate and copy strategy with fixed-size arrays © 2011 Pearson Addison-Wesley. All rights reserved

Reference-Based Linked Lists Contains nodes that are linked to one another A node contains both data and a link to the next item Access is package-private package List; class Node { int item; Node next; // constructors, accessors, } // end class Node Figure 5-5 A node © 2011 Pearson Addison-Wesley. All rights reserved

Reference-Based Linked Lists Using the Node class Node n = new Node (new Integer(6)); Node first = new Node (new Integer(9), n); Figure 5-7 Using the Node constructor to initialize a data field and a link value © 2011 Pearson Addison-Wesley. All rights reserved