public boolean offer ( E o ) { // Make a new node out of the new data element. Node newNode = new Node ( o ) ; // Check if there is already a minimum element. if ( minNode != null ) { // There is already a minimum element, so add this new element to its right. newNode . next = minNode . next ; newNode . prev = minNode ; minNode . next . prev = newNode ; minNode . next = newNode ; // Compare the new element with the minimum and update the minimum if neccessary. updateMinimum ( newNode ) ; } // There is not already a minimum element. else { // Update the new element previous and next references to refer to itself so that it forms a doubly linked // list with only one element. This leaves the data structure in a suitable condition for adding more // elements. newNode . next = newNode ; newNode . prev = newNode ; // Set the minimum element to be the new data element. minNode = newNode ; } // Increment the count of data elements in this collection. size ++ ; // Return true to indicate that the new data element was accepted into the heap. return true ; }
Inserts the specified element into this heap .