Results 1 to 2 of 2
  1. #1
    Growler is offline Member
    Join Date
    Jul 2010
    Rep Power

    Default removeMin from Heap

    I've been whiteboarding this out for the past hour, trying to understand how to implement removeMin function on a heap. I read some starter code online to give me an idea~ but am having trouble understanding this:

    1st, I need to check if the heap is empty, if it is, then we can't remove anything an therefore throw an exception to the user.

    2nd, If heap is not empty (heapSize >= 0), then I need to call my siftDown method... but I don't understand what the point of
    this is: data[0] = data[heapSize - 1];

    Java Code:
    public void removeMin() {
                if (isEmpty())
                      throw new HeapException("Heap is empty");
                else {
                      data[0] = data[heapSize - 1];      //what's this do?
                      if (heapSize > 0)
    Last edited by Growler; 10-16-2010 at 05:20 PM.

  2. #2
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Waterford, Ireland
    Rep Power


    assigns data[0] to the value of the uppermost bound of the array, at a guess

Similar Threads

  1. no heap space... need more heap
    By anupam.kumar in forum Advanced Java
    Replies: 3
    Last Post: 02-08-2010, 05:42 PM
  2. heap overflow
    By is0dvil in forum Advanced Java
    Replies: 1
    Last Post: 11-17-2009, 11:43 PM
  3. Heap memory
    By gayathri_g in forum New To Java
    Replies: 12
    Last Post: 09-10-2009, 09:45 AM
  4. How i get a JVM Heap information ?
    By Martin in forum New To Java
    Replies: 0
    Last Post: 01-15-2009, 12:03 PM
  5. Heap Sorting
    By kesav2005 in forum New To Java
    Replies: 1
    Last Post: 11-13-2007, 05:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts