CS 280 Data Structures Professor John Peterson. Statics Understanding how and when to use statics is a really tough part of Java. What situations does.

Slides:



Advertisements
Similar presentations
1 Classes and Objects in Java Parameter Passing, Delegation, Visibility Control, and Object Cleanup.
Advertisements

For(int i = 1; i
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Copyright © Recursive GCD Demo public class.
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
Review BP Dari slide pak cahyo pertemuan 7 dan pertemuan 2 dengan sedikit modifikasi.
Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
Visual Classes 1 Class: Bug 5 Objects: All Bug Objects.
Program Memory MIPS memory operations Getting Variable Addresses Advanced structures.
SORTING AND ASYMPTOTIC COMPLEXITY Lecture 12 CS2110 – Spring 2014 File searchSortAlgorithms.zip on course website (lecture notes for lectures 12, 13) contains.
1 Working with References. 2 References Every object variable is a reference to an object Also true when an object is passed as an argument When the object.
CS-1030 Dr. Mark L. Hornick 1 Constructors Copy Constructors.
Java Planning our Programs Flowcharts Arithmetic Operators.
CS 280 Data Structures Professor John Peterson. Quiz Wrapup interface Comparable { public boolean gtr(T x, T y); } class Student { public int studentNumber;
CS 280 Data Structures Professor John Peterson. Netbeans Magic What you did on Project 2 can be done much more easily if you use the refactoring menu.
Fibonacci Numbers A simple example of program design.
CS 280 Data Structures Professor John Peterson. Project Questions? /CIS280/f07/project5http://wiki.western.edu/mcis/index.php.
CS 280 Data Structures Professor John Peterson. Quiz 4 Recap Consider the following array: {2, 6, 7, 3, 4, 1, 5, 9}. Draw this in tree form and then show.
Lecture 4: Objects and Classes Classes Objects Data fields (instance variables) Methods –Instance methods –Static methods –Constructors But first…
CS 280 Data Structures Professor John Peterson. Homework #1 Remember: this is due by class Wednesday! Ask questions now or by /wiki
CS 280 Data Structures Professor John Peterson. Example: log(N) This is where things get hairy! How would you compute Log 10 (N) in a very approximate.
CS 280 Data Structures Professor John Peterson. Log Complexity int j = n; while (j > 0) { System.out.println(j); j = j / 2; /* Integer division! */ }
CS 280 Data Structures Professor John Peterson. Project 9 Questions? IS280.
Selection Sort
CS 280 Data Structures Professor John Peterson. Grading the Projects Boo-boos: Not allowing bubble sort to exit soon enough Mistakes in the heapify, especially.
CS 280 Data Structures Professor John Peterson. heapify void heapify(int i, Sortable s, int n) { // n is the limit of s int l = left(i); // 2*i+1 int.
CS 280 Data Structures Professor John Peterson. Homework / Project Note the homework isn’t due till tomorrow. Plus it’s not too hard. The project IS due.
CS 280 Data Structures Professor John Peterson. Homework Answers boolean m(int a[]) { for (int i = 0; i < a.length; i++) { for (int j = i+1; j < a.length;
Control Structures II. Why is Repetition Needed? There are many situations in which the same statements need to be executed several times. Example: Formulas.
Passing Other Objects Strings are called immutable which means that once a String object stores a value, it never changes –recall when we passed a message.
Grouping objects Arrays, Collections and Iterators 1.0.
CSE 341 Lecture 4 merge sort; basic efficiency issues Ullman slides created by Marty Stepp
Java Expressions MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation ©Akhilesh.
Selection Sort
CONTROL STATEMENTS LOOPS. WHY IS REPETITION NEEDED?  There are many situations in which the same statements need to be executed several times.  Example:
HEAPSORT The array A[1].. A[n] is sorted by treating the sub-array A[1].. A[p] as a heap: 1. Build A[1].. A[p] into a heap. 2. Exchange A[1] and A[p],
1 BUILDING JAVA PROGRAMS CHAPTER 7.2 ARRAY TRAVERSAL ALGORITHMS.
CSE 143 Lecture 16 Sorting reading: 13.1, slides created by Marty Stepp
Structured Programming Dr. Atif Alhejali Lecture 4 Modifiers Parameters passing 1Structured Programming.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Slides by Evan Gallagher
Slides by Evan Gallagher
continued on next slide
slides created by Marty Stepp and Hélène Martin
                                                                                                                                                                                                                                                
continued on next slide
continued on next slide
A simple example of program design
March 29th Odds & Ends CS 239.
Selection Sort Find the smallest value in the array. Put it in location zero. Find the second smallest value in the array and put it in location 1. Find.
ორობითი ხეები. გროვა. სორტირება გროვით.
TO COMPLETE THE FOLLOWING:
slides adapted from Marty Stepp and Hélène Martin
Stack Memory 2 (also called Call Stack)
Cs212: DataStructures Computer Science Department Lab 3 : Recursion.
Parameter Passing in Java
Computer Programming 1 introduction to JAVA Lecture 1 Instructor: Ruba A. Salamah Islamic University of Gaza.
Recursive GCD Demo public class Euclid {
slides created by Marty Stepp
slides created by Marty Stepp
class PrintOnetoTen { public static void main(String args[]) {
slides created by Marty Stepp and Hélène Martin
Sampath Kumar S Assistant Professor, SECE
CS100J Lecture 16 Previous Lecture This Lecture Programming concepts
slides adapted from Marty Stepp
CS100J Lecture 16 Previous Lecture This Lecture Programming concepts
Local variables and how to recognize them
continued on next slide
Building Java Programs
continued on next slide
Presentation transcript:

CS 280 Data Structures Professor John Peterson

Statics Understanding how and when to use statics is a really tough part of Java. What situations does it make sense in to use static variables? Static final variables? A class with only static methods? What is special about static vars/methods? What are the rules of a static method? Let’s look at how to store sort functions into statics.

heapify void heapify(int i, Sortable s, int n) { // n is the limit of s int l = left(i); // 2*i+1 int r = right(i); // 2*i+2 if (r < n) { if (s.gtr(l, i) || s.gtr(r, i)) { if (s.gtr(l,r)) { s.swap(i,l); heapify(l,s,n); } else { s.swap(i,r); heapify(r,s,n); }}} // Missing } in old slide else if (l < n) { if (s.gtr(l,i)) swap(i,l); } // Bug in old slide