1 CompSci 105 SS 2005 Principles of Computer Science Lecture 11: Linked Lists Lecturer: Santokh Singh Assignment 2 due tomorrow, i.e. Friday 21 Jan 2005.

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

Delta Confidential 1 5/29 – 6/6, 2001 SAP R/3 V4.6c PP Module Order Change Management(OCM)
You have been given a mission and a code. Use the code to complete the mission and you will save the world from obliteration…
CS Data Structures I Chapter 6 Stacks I 2 Topics ADT Stack Stack Operations Using ADT Stack Line editor Bracket checking Special-Palindromes Implementation.
Advanced Piloting Cruise Plot.
Chapter 6 Structures and Classes. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 6-2 Learning Objectives Structures Structure types Structures.
Chapter 1 The Study of Body Function Image PowerPoint
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 11: Structure and Union Types Problem Solving & Program Design.
11 Copyright © 2005, Oracle. All rights reserved. Using Arrays and Collections.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
Determine Eligibility Chapter 4. Determine Eligibility 4-2 Objectives Search for Customer on database Enter application signed date and eligibility determination.
My Alphabet Book abcdefghijklm nopqrstuvwxyz.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Addition Facts
Year 6 mental test 10 second questions
Lecture 15 Linked Lists part 2
Richmond House, Liverpool (1) 26 th January 2004.
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 17 Linked Lists.
COMP171 Fall 2005 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.
Linked Lists Chapter 4.
Data Structures: A Pseudocode Approach with C
Data Structures ADT List
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 4: Linked Lists Data Abstraction & Problem Solving with.
1 CSE1301 Computer Programming: Lecture 27 List Manipulation.
ADTs unsorted List and Sorted List
Data Structures Using C++
LIST PROCESSING.
Double-Linked Lists and Circular Lists
ABC Technology Project
1 Undirected Breadth First Search F A BCG DE H 2 F A BCG DE H Queue: A get Undiscovered Fringe Finished Active 0 distance from A visit(A)
VOORBLAD.
Review Pseudo Code Basic elements of Pseudo code
1 Breadth First Search s s Undiscovered Discovered Finished Queue: s Top of queue 2 1 Shortest path from s.
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
The List ADT Textbook Sections
BIOLOGY AUGUST 2013 OPENING ASSIGNMENTS. AUGUST 7, 2013  Question goes here!
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
© 2012 National Heart Foundation of Australia. Slide 2.
Copyright © 2013 by John Wiley & Sons. All rights reserved. HOW TO CREATE LINKED LISTS FROM SCRATCH CHAPTER Slides by Rick Giles 16 Only Linked List Part.
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
GG Consulting, LLC I-SUITE. Source: TEA SHARS Frequently asked questions 2.
Addition 1’s to 20.
25 seconds left…...
Januar MDMDFSSMDMDFSSS
Week 1.
We will resume in: 25 Minutes.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Intracellular Compartments and Transport
PSSA Preparation.
Immunobiology: The Immune System in Health & Disease Sixth Edition
Essential Cell Biology
Immunobiology: The Immune System in Health & Disease Sixth Edition
CpSc 3220 Designing a Database
Data Structures Using C++ 2E
Linked Lists. Preliminaries Options for implementing an ADT List Array Has a fixed size Data must be shifted during insertions and deletions Dynamic array.
1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.
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.
1 CompSci 105 SS 2005 Principles of Computer Science Lecture 9: Implementing ADTs Lecturer: Santokh Singh Please try to Understand All concepts involved.
1 Lecture 15: Big O Notation (Wednesday) Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science Test See Web for Details Don’t be deleted!
Presentation transcript:

1 CompSci 105 SS 2005 Principles of Computer Science Lecture 11: Linked Lists Lecturer: Santokh Singh Assignment 2 due tomorrow, i.e. Friday 21 Jan 2005 by 4 pm

2 Java Reference Variables Integer intRef = new Integer(5); intRef: Textbook, pp

3 What does equal mean?

4 Equality of References Integer p, q; p = new Integer(5); q = new Integer(5); if ( p == q ) println(Equal); else println(Not); p: q:

5 Equality of References Integer p, q; p = new Integer(5); if ( p.equals(q) ) println(Equal); else println(Not); p: q:

6 References and Objects Example: Parameter Passing Example: Resizable Arrays Linked Lists The Node class Lists as Recursive Structures Displaying a Linked List Inserting and Deleting Elements Implementing the ADT List

7 Example: Parameters public void changeNumber( Integer n ); { n = new Integer(5); } Integer p; p = new Integer(9); changeNumber(p); println(p); Textbook, pp. 157

8 Example: Arrays int[] a = new int[5]; a[0] = 3;

9 What is the output? int a = 3; int b = a; b = 4; System.out.println(a); int[] c = {3}; int[] d = c; d[0] = 4; System.out.println(c[0]); Textbook, pp. 155 Exercise L10.1

10 References and Objects Example: Parameter Passing Example: Resizable Arrays Linked Lists The Node class Lists as Recursive Structures Displaying a Linked List Inserting and Deleting Elements Implementing the ADT List

11 List ADT 1.Milk 2.Eggs 3.Butter 4.Apples 5.Bread 6.Chicken Textbook, p. 111ff createList() isEmpty() size() add( index, item) remove(index) removeAll() get(index)

12 A few list ADT operations list.get(3)

13 A few list ADT operations list.get(3) list.remove(3)

14 A few list ADT operations list.get(3) list.remove(3) list.add(3, butter)

15 A few list ADT operations list.get(3) list.remove(3) list.add(3, butter) list.add(3, beer)

16 Resizable Arrays Textbook, pp myArray: 0123

17 Resizable Arrays Textbook, pp myArray : 0123 tempArray:

18 Resizable Arrays Textbook, pp myArray: tempArray :

19 Resizable Arrays Textbook, pp myArray : tempArray :

20 Resizable Arrays Textbook, pp myArray : tempArray : See Java code in textbook on p. 158

21 References and Objects Example: Parameter Passing Example: Resizable Arrays Linked Lists The Node class Lists as Recursive Structures Displaying a Linked List Inserting and Deleting Elements Implementing the ADT List

22 A few list ADT operations list.get(3) list.remove(3) list.add(3, butter) list.add(3, beer)

23 A Node Data Structure public class Node { private Objectitem; private Nodenext; } Beer Wine Textbook, pp. 161

24 Recursive Definition Milk Eggs Butter Apples Bread Chicken A List is a first item, followed by a List

25 Terminology myList Beer Wine Milk

26 ListReferenceBased Class public class ListReferenceBased { private Node head; private int numItems; } Beer Wine Milk 3 Textbook, pp. 175

27 Node class public class Node { private Objectitem; private Nodenext; public Object getItem() {return item;} public Node getNext() {return next;} public void setItem(Object i) {item=i;} public void setNext(Node n) {next=n;} } Beer Textbook, pp. 161

28 References and Objects Example: Parameter Passing Example: Resizable Arrays Linked Lists The Node class Lists as Recursive Structures Displaying a Linked List Inserting and Deleting Elements Implementing the ADT List

29 public void printList( ) { Node curr = head; while (curr != null ) { System.out.println( curr.getItem() ); curr = curr.getNext(); } Beer Wine Milk head Textbook, pp. 164