Advertisement
Aldin-SXR

delMax()

May 6th, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.32 KB | None | 0 0
  1. /* Remove the maximum (max. priority) item  */
  2. public Item delMax() {
  3.     Item max = pq[1];                               // 1
  4.     swap(1, length--);                              // 2
  5.     pq[length + 1] = null;                          // 3
  6.          
  7.     if (length > 0 && length == pq.length / 4) {    // 4
  8.         resize(pq.length / 2);                      // 4
  9.     }
  10.        
  11.     sink(1);                                        // 5
  12.     return max;                                     // 6
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement