Like Tree1Likes
  • 1 Post By brewbuck

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

This is a discussion on How would we output from smallest to largest in a heap data stucture? within the C++ Programming forums, part of the General Programming Boards category; Here is the heap I am looking at, As you can see from the heap tree, the order of the ...

  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,
    Name:  Max-heap.png
Views: 134
Size:  20.5 KB

    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
    452
    Sort it.
    "All that we see or seem
    Is but a dream within a dream." - Poe

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,230
    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.)
    iMalc likes this.
    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, 10: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21