Thread: what is the algorithm for arranging a heap..

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    what is the algorithm for arranging a heap..

    a heap is a binary tree where the root is the biggest
    so if i get a root where its not the biggest
    how to transform recursivly
    6
    8 4
    7

    into
    8
    7 4
    6

    i know that i need to switch between the root and the biggest sun
    but in this example i still need to go the next level down
    so how to write that??

  2. #2
    Tha 1 Sick RAT
    Join Date
    Dec 2003
    Posts
    271
    Stop spamming the DOS attacking the forums.
    I noticed you're posting a lot in just 24 hours.
    My advice is that you should psuedo code your program, convert it into logical pieces of code google any stumbling blocks and if you're then lost post.
    Don't post at the 1st sign of trouble. put yer mind and resources to work for you 1st.
    A hundred Elephants can knock down the walls of a fortress... One diseased rat can kill everyone inside

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    The root must be exchanged with the larger of its children. Doing so may have caused the exchanged child to lose the heap property, so you re-heapify on that, continuing to go down the tree until you reach a node that does not need to be re-heapified.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. heap
    By George2 in forum Windows Programming
    Replies: 2
    Last Post: 11-10-2007, 11:49 PM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. heap question
    By mackol in forum C Programming
    Replies: 1
    Last Post: 11-30-2002, 05:03 AM