Einzelnen Beitrag anzeigen

Benutzerbild von DGL-luke
DGL-luke

Registriert seit: 1. Apr 2005
Ort: Bad Tölz
4.149 Beiträge
 
Delphi 2006 Professional
 
#4

Re: Build Heap And Heapsort Without Array

  Alt 1. Mai 2006, 19:01
i didn't say it produced a sorted heap, which in your case would be a MAX-Heap, right?

well, isn't a binary tree just about the same thing? You're right, I'm just 17, and I only took a glance at wikipedia to get the structure of a binary heap.

The rest is merely pointer acrobatics...

Just looked at wikipedia again... "a heap is an abstract data structure, mostly based on trees" (rough translation )

So what does your tree look like? Is it just unsorted?

EDIT: btw, the "too lazy to write that now" comment above should not suggest that i understand heapsorting in any way (well, it does, but honestly I don't know - well, wikipedia educates)

EDIT: OK, I think I got it about now - we need a heap that maintains its (existing) order so we can just pick out the biggest element one after the other.

EDIT: and yes, there are sources saying a heap is a binary tree which is sorted.

As I just feel like it, I'll outline a simple heap class based on THeapNode. Stand By

EDIT: Well, I'll try it's not that easy. But it should be rather easy to make a (balanced, sort of) binary tree into a sorted heap. Just take the lowest leaf and check if its value is less than its parent's value. if it is, check the next leaf. if it is not, swap them.
Lukas Erlacher
Suche Grafiktablett. Spenden/Gebrauchtangebote willkommen.
Gotteskrieger gesucht!
For it is the chief characteristic of the religion of science that it works. - Isaac Asimov, Foundation I, Buch 1
  Mit Zitat antworten Zitat