Thread: How would we output from smallest to largest in a heap data stucture?

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    5

    How would we output from smallest to largest in a heap data stucture?

    Here is the heap I am looking at,
    How would we output from smallest to largest in a heap data stucture?-max-heap-png

    As you can see from the heap tree, the order of the nodes are everywhere. The number 1 is on the right side and the number 2 is bottom left. How would I make it so I can output those numbers in order?

  2. #2
    -bleh-
    Join Date
    Aug 2010
    Location
    somewhere in this universe
    Posts
    463
    Sort it.
    "All that we see or seem
    Is but a dream within a dream." - Poe

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Step 1: Begin by NOT storing the values in a largest-first heap. That's like jumping out of an airplane with SCUBA gear instead of a parachute.

    (More helpfully, had you used a smallest-first heap instead of a largest-first heap, you'd only be a heap-sort away from solving the problem.)
    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. Sum up the largest and smallest ones
    By programmer1 in forum C Programming
    Replies: 8
    Last Post: 11-08-2011, 11:35 AM
  2. Kth largest &kth smallest
    By baffleddreams in forum C Programming
    Replies: 16
    Last Post: 10-01-2010, 05:08 PM
  3. Replies: 22
    Last Post: 05-29-2009, 05:44 PM
  4. smallest largest number
    By manzoor in forum C++ Programming
    Replies: 10
    Last Post: 05-12-2008, 07:56 AM
  5. largest and smallest
    By eldemonio in forum C Programming
    Replies: 9
    Last Post: 10-15-2007, 02:00 PM