Hipsort — разлика између измена

435 бајтова уклоњено ,  пре 9 година
Нема описа измене
jasan način uključivanja A[i] u hip: A[i] se upoređuje sa većim od sinova, i
zamenjuje se sa njim ako je potrebno. Sa zamenama se nastavlja naniže niz stablo, dok prethodna vrednost elementa A[i] ne dođe do mesta na kome je veća od oba sina.
== ExamplePrimer ==
Neka { 6, 5, 3, 1, 8, 7, 2, 4 } bude niz koji želimo da sortiramo od najmanjeg do najvećeg.
Let { 6, 5, 3, 1, 8, 7, 2, 4 } be the list that we want to sort from the smallest to the largest. (NOTE, for 'Building the Heap' step: Larger nodes don't stay below smaller node parents. They are swapped with parents, and then recursively checked if another swap is needed, to keep larger numbers above smaller numbers on the heap binary tree.)
[[File:Heapsort-example.gif|350px|thumb|right|An example on heapsort.]]
'''1. BuildFormiranje the heaphipa'''
{| class="wikitable"
|-
! HeapHip !! newly addednovi element !! swapzamena elementselemenata
|-
| nul || 6 ||
|}
 
'''2. SortingSortiranje.'''
{| class="wikitable"
|-
! HeapHip !! swapzamena elementselemenata !! deletebrisanje elementelemenata !! sortedsortiran arrayniz !! detailskoraci
|-
| '''8''', 6, 7, 4, 5, 3, 2, '''1''' || 8, 1 || || || swapzamena 8 andi 1 in order to delete 8 from heap
|-
| 1, 6, 7, 4, 5, 3, 2, '''8''' || || 8 || || deletebrisanje 8 fromiz heaphipa andi addubacivanje tou sorted arrayniz
|-
| '''1''', 6, '''7''', 4, 5, 3, 2 || 1, 7 || || 8 || swapzamena 1 andi 7 asjer theynisu areu notporetku inpravila order in the heaphipa
|-
| 7, 6, '''1''', 4, 5, '''3''', 2 || 1, 3 || || 8 || swapzamena 1 andi 3 asjer theynisu areu notporetku in order in the heappravila hipa
|-
| '''7''', 6, 3, 4, 5, 1, '''2''' || 7, 2 || || 8 || swapzamena 7 andi 2 inza order to deletebrisanje 7 fromiz heaphipa
|-
| 2, 6, 3, 4, 5, 1, '''7''' || || 7 || 8 || deletebrisanje 78 fromiz heaphipa andi addubacivanje tou sorted arrayniz
|-
| '''2''', '''6''', 3, 4, 5, 1 || 2, 6 || || 7, 8 || swapzamena 2 andi 6 asjer theynisu areu notporetku inpravila order in the heaphipa
|-
| 6, '''2''', 3, 4, '''5''', 1 || 2, 5 || || 7, 8 || swapzamena 2 andi 5 asjer theynisu areu notporetku inpravila order in the heaphipa
|-
| '''6''', 5, 3, 4, 2, '''1'''|| 6, 1 || || 7, 8 || swapzamena 6 andi 1 inza order to deletebrisanje 6 fromiz heaphipa
|-
| 1, 5, 3, 4, 2, '''6''' || || 6 || 7, 8 || deletebrisanje 6 fromiz heaphipa andi addubacivanje tou sorted arrayniz
|-
| '''1''', '''5''', 3, 4, 2 || 1, 5 || || 6, 7, 8 || swapzamena 1 andi 5 asjer theynisu areu notporetku in order in the heappravila hipa
|-
| 5, '''1''', 3, '''4''', 2 || 1, 4 || || 6, 7, 8 || swapzamena 1 andi 4 asjer theynisu areu notporetku in order in the heappravila hipa
|-
| '''5''', 4, 3, 1, '''2''' || 5, 2 || || 6, 7, 8 || swapzamena 5 andi 2 inza order to deletebrisanje 5 from heapiz hipa
|-
| 2, 4, 3, 1, '''5''' || || 5 || 6, 7, 8 || deletebrisanje 5 fromiz heaphipa andi addubacivanje to sorted arrayu niz
|-
| '''2''', '''4''', 3, 1 || 2, 4 || || 5, 6, 7, 8 || swapzamena 2 andi 4 asjer theynisu areu notporetku in order in the heappravila hipa
|-
| '''4''', 2, 3, '''1''' || 4, 1 || || 5, 6, 7, 8 || swapzamena 4 andi 1 inza order to deletebrisanje 4 from heapiz hipa
|-
| 1, 2, 3, '''4''' || || 4 || 5, 6, 7, 8 || deletebrisanje 4 fromiz heaphipa andi addubacivanje to sorted arrayu niz
|-
| '''1''', 2, '''3''' || 1, 3 || || 4, 5, 6, 7, 8 || swapzamena 1 andi 3 asjer theynisu areu notporetku in order in the heappravila hipa
|-
| '''3''', 2, '''1''' || 3, 1 || || 4, 5, 6, 7, 8 || swapzamena 3 andi 1 inza order to deletebrisanje 3 fromiz heaphipa
|-
| 1, 2, '''3''' || || 3 || 4, 5, 6, 7, 8 || deletebrisanje 3 fromiz heaphipa andi addubacivanje to sorted arrayu niz
|-
| '''1''', '''2''' || 1, 2 || || 3, 4, 5, 6, 7, 8 || swapzamena 1 andi 2 asjer theynisu areu notporetku in order in the heappravila hipa
|-
| '''2''', '''1''' || 2, 1 || || 3, 4, 5, 6, 7, 8 || swapzamena 2 andi 1 inza order to deletebrisanje 2 fromiz heaphipa
|-
| 1, '''2''' || || 2 || 3, 4, 5, 6, 7, 8 || deletebrisanje 2 fromiz heaphipa andi addubacivanje to sorted arrayu niz
|-
| '''1''' || || 1 || 2, 3, 4, 5, 6, 7, 8 || deletebrisanje 1 fromiz heaphipa andi addubacivanje to sorted arrayu niz
|-
| || || || 1, 2, 3, 4, 5, 6, 7, 8 || completedkraj
|}
 
66

измена