LinkedIntList(int n) Write a constructor for LinkedIntList that accepts an int n parameter and makes a list of the number from 0 to n new LinkedIntList(3)

Slides:



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

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.
CHAPTER 7 Queues.
An Array-Based Implementation of the ADT List public class ListArrayBased implements ListInterface { private static final int MAX_LIST = 50; private Object.
The Template Class Chain Chain Linear list. Each element is stored in a node. Nodes are linked together using pointers.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 17: Linked Lists.
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.
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.
Lab 7 Queue ADT. OVERVIEW The queue is one example of a constrained linear data structure. The elements in a queue are ordered from least recently added.
CSE 143 Lecture 10 Linked List Basics reading: slides created by Marty Stepp
1 Data Structures CSCI 132, Spring 2014 Lecture 20 Linked Lists.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 17: Linked Lists.
“When we quit thinking primarily about ourselves and our own self-preservation, we undergo a truly heroic transformation of consciousness.” – Joseph Campbell.
(c) University of Washington16-1 CSC 143 Java Linked Lists Reading: Ch. 20.
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.
Ordered Linked Lists using Abstract Data Types (ADT) in Java Presented by: Andrew Aken.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Sorted Lists Chapter Chapter Contents Specifications for the ADT Sorted List Using the ADT Sorted List A Linked Implementation The Method add The.
slides adapted from Marty Stepp and Hélène Martin
Linked Lists A formal data structure. Linked Lists Collections of data items “lined up in a row” Inserts and deletes can be done anywhere in the list.
Linked Data Structures
Stack: a Linked Implementation
Section 2.6 Linked List StringLog ADT Implementation
The List ADT.
Building Java Programs Chapter 16
Building Java Programs
Doubly Linked List Review - We are writing this code
Sections 8.7 – 8.8 Balancing a Binary Search Tree.
Programming Abstractions
slides created by Marty Stepp
Notes on Assignment 1 Your code will have several classes, most notably the class that represents the entire list data structure, and the class.
Wednesday Questions How do I debug? We love to teach this at IPL/OH!
Linked node problem 3 What set of statements turns this picture:
Prof. Neary Adapted from slides by Dr. Katherine Gibson
Linked node problem 3 What set of statements turns this picture:
LinkedIntList(int n) Write a constructor for LinkedIntList that accepts an int n parameter and makes a list of the number from 0 to n new LinkedIntList(3)
slides created by Marty Stepp and Ethan Apter
Building Java Programs
Building Java Programs
Lecture 7: Linked List Basics reading: 16.2
More Linked Lists and Loops Based on slides by Ethan Apter
תירגול 9 אובייקטים.
Programming Abstractions
Programming II (CS300) Chapter 07: Linked Lists and Iterators
changing a list There are only two ways to change a linked list:
Building Java Programs
slides adapted from Marty Stepp and Hélène Martin
slides created by Marty Stepp and Hélène Martin
Building Java Programs
Building Java Programs
slides created by Marty Stepp
Lecture 8: Complex Linked List Code reading: 16.2 – 16.3
Lecture 14 Linked Lists CSE /26/2018.
LinkedIntList(int n) Write a constructor for LinkedIntList that accepts an int n parameter and makes a list of the number from 0 to n new LinkedIntList(3)
Building Java Programs
CSC 143 Java Linked Lists.
slides created by Marty Stepp
slides created by Alyssa Harding
Recursive Objects Singly Linked Lists.
slides adapted from Marty Stepp
Building Java Programs
Programming II (CS300) Chapter 07: Linked Lists
Lecture 7: Linked List Basics reading: 16.2
slides adapted from Marty Stepp
Wednesday Questions How do I debug? We love to teach this at IPL/OH!
slides created by Marty Stepp
slides created by Ethan Apter
slides created by Marty Stepp
slides created by Marty Stepp
slides created by Marty Stepp and Hélène Martin
Presentation transcript:

LinkedIntList(int n) Write a constructor for LinkedIntList that accepts an int n parameter and makes a list of the number from 0 to n new LinkedIntList(3) : front = data next 3 data next 2 data next 1 data next

addSorted Write a method addSorted that accepts an int as a parameter and adds it to a sorted list in sorted order. Before addSorted(17) : After addSorted(17) : front = data next -4 data next 8 data next 22 element 0 element 1 element 2 front = data next -4 data next 8 data next 17 data next 22 element 0 element 1 element 2 element 3

changing a list There are only two ways to change a linked list: Change the value of front (modify the front of the list) Change the value of <node>.next (modify middle or end of list to point somewhere else) Implications: To add in the middle, need a reference to the previous node Front is often a special case

Common cases middle: "typical" case in the middle of an existing list back: special case at the back of an existing list front: special case at the front of an existing list empty: special case of an empty list

Other list features Add the following methods to the LinkedIntList: size isEmpty clear toString indexOf contains Add a size field to the list to return its size more efficiently. Add preconditions and exception tests to appropriate methods.