Hw #6 due on 3/25… Java, from the details to the bigger picture Spamventure! From the details, the big (ASCII) picture after break… emanning msheely, 1432.

Slides:



Advertisements
Similar presentations
Lecture 3 Some commonly used C programming tricks. The system command Project No. 1: A warm-up project.
Advertisements

Chapter 22 Implementing lists: linked implementations.
Linked Lists Linear collections.
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)
COSC 1P03 Data Structures and Abstraction 10.1 The List If A is success in life, then A equals x plus y plus z. Work is x; y is play; and z is keeping.
David Weinberg presents Linked Lists: The Background  Linked Lists are similar to ArrayLists in their appearance and method of manipulation  They do.
1 Various Methods of Populating Arrays Randomly generated integers.
Written by: Dr. JJ Shepherd
Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. It is common to use two nested loops when filling or searching: for.
CSE 143 Lecture 22: Advanced List Implementation (ADTs; interfaces; abstract classes; inner classes; generics; iterators)
Introduction to Computer Science Recursive Link Operations MergeSort Unit 18.
1 CS 201 Dynamic Data Structures Debzani Deb. 2 Run time memory layout When a program is loaded into memory, it is organized into four areas of memory.
Lecture 6: Linked Lists Linked lists Insert Delete Lookup Doubly-linked lists.
Chapter 10Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Announcements/Reminders l Project 6 due on Thursday March 31 l Exam.
Chapter 10Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 10 l Vectors l Linked Data Structures Dynamic Data Structures.
CM0551 Exam Prep. What are an algorithm’s time and space complexity? (2 marks) Answer: The growth rate of the algorithm’s time requirement and the computer.
1 CSC 222: Object-Oriented Programming Spring 2012 Object-oriented design  example: word frequencies w/ parallel lists  exception handling  System.out.format.
Information and Computer Sciences University of Hawaii, Manoa
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
Arrays An array is a data structure that consists of an ordered collection of similar items (where “similar items” means items of the same type.) An array.
COMP 103 Linked Lists. 2 RECAP-TODAY RECAP  Linked Structures: LinkedNode  Iterating and printing Linked Nodes  Inserting and removing Linked Nodes.
ليست هاي پيوندي Linked Lists ساختمان داده ها و الگوريتم ها.
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
2014-T2 Lecture 19 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Lindsay Groves, Peter Andreae, and John.
CSE 143 Lecture 10 Linked List Basics reading: slides created by Marty Stepp
Interfaces, Classes, Collections School of Engineering and Computer Science, Victoria University of Wellington COMP T2 Lecture 3 Thomas Kuehne.
(c) University of Washington16-1 CSC 143 Java Linked Lists Reading: Ch. 20.
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.
CSS446 Spring 2014 Nan Wang.  To understand the implementation of linked lists and array lists  To analyze the efficiency of fundamental operations.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
Linked lists. Data structures to store a collection of items Data structures to store a collection of items are commonly used Typical operations on such.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
COP 3275 – Character Strings Instructor: Diego Rivera-Gutierrez.
Interfaces, Classes, Collections School of Engineering and Computer Science, Victoria University of Wellington COMP T2 Lecture 3 Marcus Frean.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
When constructing a two-dimensional array, specify how many rows and columns are needed: final int ROWS = 3; final int COLUMNS = 3; String[][] board =
Data Structures Arrays and Lists Part 2 More List Operations.
M180: Data Structures & Algorithms in Java Stacks Arab Open University 1.
slides adapted from Marty Stepp and Hélène Martin
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
C Tutorial - Pointers CS 537 – Introduction to Operating Systems.
Building Java Programs
Programming Abstractions
slides created by Marty Stepp
Pointers and Dynamic Variables
Prof. Neary Adapted from slides by Dr. Katherine Gibson
CSE 143 Lecture 9 References and Linked Nodes reading: 16.1
slides created by Marty Stepp and Ethan Apter
Building Java Programs
Building Java Programs
CSE 143 Lecture 6 References and Linked Nodes reading: 16.1
Lecture 7: Linked List Basics reading: 16.2
Programming Abstractions
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
CSE 143 Lecture 5 References and Linked Nodes
Building Java Programs
slides created by Marty Stepp
slides adapted from Marty Stepp
Building Java Programs
Lecture 7: Linked List Basics reading: 16.2
Lecture 6: References and linked nodes reading: 16.1
CSE 143 Lecture 7 References and Linked Nodes reading: 16.1
slides adapted from Marty Stepp
Linked Lists and Loops based on slides by Ethan Apter
slides created by Ethan Apter
Linked Lists.
slides created by Marty Stepp
Presentation transcript:

Hw #6 due on 3/25… Java, from the details to the bigger picture Spamventure! From the details, the big (ASCII) picture after break… emanning msheely, 1432 lines!! slam mnaval, 859 lines! further adventures in cs60 !

Hw #6 due on 3/25… Java, from the details to the bigger picture after break… emanning msheely, 1432 lines!! slam mnaval, 859 lines! further adventures in cs60 !

Big Java…

huge libraries of classes (data structures)

Even Math add Prof. Williams!

Java structures data

List L; mySizemyHead List myFirstmyRest "a" myFirstmyRest "c" null myFirstmyRest "b" 3 Java structures data ListNode Singly-linked list data structure L.addToFront("c"); L.addToFront("b"); L.addToFront("a"); List L L = new List();

List L; Java structures data List L null I guess this reference is a null space… All objects are handled by reference. Empty references are null.

List L; mySizemyHead List 0 Java structures data List L L = new List(); null int ListNode

List L; mySizemyHead List myFirstmyRest "c" null 1 Java structures data ListNode L.addToFront("c"); List L L = new List();

List L; mySizemyHead List myFirstmyRest "c" null myFirstmyRest "b" 2 Java structures data ListNode L.addToFront("c"); L.addToFront("b"); List L L = new List();

List L; mySizemyHead List myFirstmyRest "a" myFirstmyRest "c" null myFirstmyRest "b" 3 Java structures data ListNode L.addToFront("c"); L.addToFront("b"); L.addToFront("a"); List L L = new List();

mySizemyHead List myFirstmyRest "a" myFirstmyRest "c" null myFirstmyRest "b" 3 List class ListNode ListNode class !

addToFront public void addToFront( String str ) { ListNode LN = new ListNode( str, null ); // 1 LN.myRest = this.myHead; // 2 this.myHead = LN; // 3 this.mySize += 1; // 4 } public void addToFront( String str ) { this.myHead = new ListNode( str, myHead ); // 1-3 this.mySize += 1; // 4 L.addToFront("a"); whoa! same thing:

removeFirst L.removeFirst( ); mySizemyHead List myFirstmyRest "c" null myFirstmyRest "b" 2 ListNode before after L List (before) intListNode

removeFirst L.removeFirst( ); mySizemyHead List myFirstmyRest "c" null myFirstmyRest "b" 2 ListNode before mySizemyHead List 1 after myFirstmyRest "c" null ListNode L List (before) L List (after) intListNode intListNode return value: ?

removeFirst L.removeFirst( ); mySizemyHead List myFirstmyRest "c" null myFirstmyRest "b" 2 ListNode before mySizemyHead List 1 after myFirstmyRest "c" null ListNode L List (before) L List (after) intListNode intListNode return value:

Quiz public ListNode removeFirst( ) { ListNode result = if return result; } (1) What is the result? (2) We need an if – why?! (3) Fix the list up … Write the removeFirst method… Name(s): ________________________ Step (3) is one to remember! (4) Return.

Quiz public ListNode removeFirst( ) { ListNode result = return result; } (1) Cut the node out and give it a name. (2) "Fix up" the List ( this object) (…) Return the node you cut out. (3) What have we forgotten?! Write the removeFirst method… Try this on the back page first… Step (3) is one to remember!

How many? Why have both the mySize field and a length() method?

How many? checks the length by actually walking the list (1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! for loop!

How many? checks the length by actually walking the list (1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! while loops do the same four things…

this List Walking the list… (1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body!

(1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! this node List ListNode count int 0 Heap vs. stack ? What is node pointing to??

(1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! this node List ListNode count int 0

(1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! this node List ListNode count int 1

(1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! this node List ListNode count int 1 What is node now pointing to??

(1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! this node List ListNode count int 1

(1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! this node List ListNode count int 2

(1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! this node List ListNode count int 2

(1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! this node List ListNode count int 2

(1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! this node List ListNode count int 3

(1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! this node List ListNode count int 3 What will node now point to??

(1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! this node List ListNode count int 3 Nothing! null the loop exits, returning count …

this List Walking the list… (1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! too slow!

this List Walking the list… (1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! Sprinting

(1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! this node List ListNode count int 0

(1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! this node List ListNode count int 0

(1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! this node List ListNode count int 1

(1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! this node List ListNode count int 1

(1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! this node List ListNode count int 1

(1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! this node List ListNode count int 2

(1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! this node List ListNode count int 2

(1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! this node List ListNode count int 2

(1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! this node List ListNode count int 3

(1) Declare + initialize a "runner" variable (2) Test! (4) Update + go back to step 2 (3) Loop body! this node List ListNode count int 3 Done! null the loop exits, returning count …

More loops: toString Racket style!

More loops: get "Big errors" are handled in Java by throwing exceptions loops until k == pos

More loops: equals loops for the full list

add L.add( "d" ); mySizemyHead List myFirstmyRest "c" null myFirstmyRest "b" 2 ListNode before adds to the end of the List…

L.add( "d" ); mySizemyHead List myFirstmyRest "c" null myFirstmyRest "b" 2 ListNode before mySizemyHead List myFirstmyRest "c" myFirstmyRest "b" 3 ListNode after myFirstmyRest "d" null ListNode add adds to the end of the List…

Try it! add public void add( String str ) { ListNode LN = new ListNode(, ); } (1) Handle the empty case (2) If nonempty, write a loop ! (3) How far to loop? (4) and when the loop ends…? (0) Make a new ListNode

"Base Case" L.add( "b" ); mySizemyHead List 0 before mySizemyHead List 1 after myFirstmyRest "b" null ListNode null this List this List

Try it! (1) Handle the empty case (2) If nonempty, write a loop ! (3) How far to loop? (4) and when the loop ends…? (0) Make a new ListNode public void add( String str ) { ListNode end = new ListNode(, ); if (this.myHead == null) { } else { } Write the add method, which adds a new ListNode at the end.

this node List ListNode Our example while loop… (1) You need a different test! (2) What do you need in the loop and after it?

Try it! (1) Handle the empty case (2) If nonempty, write a loop ! (3) Loop until node.myRest == null (4) Add end at end of loop. (0) Make a new ListNode public void add( String str ) { ListNode end = new ListNode( str, null ); if (this.myHead == null) { this.myHead = end; } else { ListNode node = this.myHead; while (node.myRest != null) { node = node.myRest; } node.myRest = end; } this.mySize += 1; } Write the add method, which adds a new ListNode at the end. (5) Don't forget!

Lists vs. Arrays… mySizemyHead List L myFirstmyRest "c" myFirstmyRest "b" 3 ListNode List myFirstmyRest "d" null ListNode L

Lists vs. Arrays… mySizemyHead List L myFirstmyRest "c" myFirstmyRest "b" 3 ListNode List myFirstmyRest "d" null ListNode a single, set length 1 type of element indexing ~ Python no built-in slicing traverse with loops… L Array length A[0] String[] A 3 A[1]A[2] "c" "b" "d" A We should end with Arrays' upside…

Lists vs. Arrays… Let's scrapbook it! I cherish my Java!

other methods in hw6pr2 split merge ( "d" "b" "e" "c" "a" ) ( "d" "b" "e" )( "c" "a" ) ( "b" "d" "e" )( "a" "c" ) ( "a" "b" "c" "d" "e" )

Mergesort! split merge ( "d" "b" "e" "c" "a" ) ( "d" "b" "e" )( "c" "a" ) ( "b" "d" "e" )( "a" "c" ) ( "a" "b" "c" "d" "e" ) What has to happen within these pink arrows?

Mergesort! split merge ( "d" "b" "e" "c" "a" ) ( "d" "b" "e" )( "c" "a" ) ( "b" "d" "e" )( "a" "c" ) ( "a" "b" "c" "d" "e" ) mergesort

After break? Java Data-structuring details Applications plus, lots more data-structuring details

Prof Lewis! Pixels! The week after spring break…

Have a great spring break! My plans are for maximum Java!