Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Heap Implementation Question!

    I'm writing a Heap implementation using an array. I'm having trouble writing the sorting part of it, such as inserting items into a heap and sorting them max term on top and also min term on top. Can anybody help?

    if so I'll post the code i've written so far.

    (u might be wondering why I'm implementing a heap code, it's for class =)

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    We will not write the code for you as this is a school assignment. I remember all too well how much fun (not) those were to write in my computer science courses at college.

    Just think about how the algorith works then think what you need to do to accomplish it.

    Then if you have a question on how to something in the language you are using then ask a specific question about the language.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Think about writing a trickleup() method. When you add an item to the heap, trickleup() it. This should just keep swapping it up until it shouldn't any longer.

    Your teacher should have went over stuff like that in class...


  •  

    Posting Permissions

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