AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

Build Heap And Heapsort Without Array

Ein Thema von sk.Silvia · begonnen am 1. Mai 2006 · letzter Beitrag vom 13. Mai 2006
 
tigerman33

Registriert seit: 30. Jul 2005
Ort: München
423 Beiträge
 
Delphi 2005 Professional
 
#6

Re: Build Heap And Heapsort Without Array (Sift-operation)

  Alt 2. Mai 2006, 07:03
Wikipedia article explaining heapsort/sift:
Zitat von Wikipedia:
Code:
function sift(a, start, count) {
     var int root := start, child

     while root * 2 + 1 < count { 
         child := root * 2 + 1 // Ignore this--you can access a node's children much easier! :)

         if child < count - 1 and a[child] < a[child + 1] // Choose the larger of the sons, if there are two

             child := child + 1

         if a[root] < a[child] // If root node is too small...
             swap(a[root], a[child]) // Swap it with the previously determined larger son
             root := child // ...and keep track of where it is now.
               // This way, on the next loop iteration the subtree that has the just-moved node as its root will be sifted into
               // Another possible way here would have been to use recursion
         else
             return
     }
 }
PS: Yeah, I know this isn't really C-code. Just wanted the syntax highlighting...
Christian
Der Computer hilft mir, Probleme zu lösen, die ich ohne Computer nicht hätte.
  Mit Zitat antworten Zitat
 

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:41 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz