Download presentation
Presentation is loading. Please wait.
1
CS 280 Data Structures Professor John Peterson
2
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.
3
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.