1 / 18

Urejanje s kopico

Urejanje s kopico . Ideja: kopico najprej izgradimo, nato pa iz kopice vzamemo koren in ga damo v skladišče. Zadnji element v kopici damo v koren in ga pogrezamo. Postopek ponavljamo, dokler se kopica ne izprazni(vsi elementi so v skladišču).

dianne
Download Presentation

Urejanje s kopico

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Urejanje s kopico Ideja: kopico najprej izgradimo, nato pa iz kopice vzamemo koren in ga damo v skladišče. Zadnji element v kopici damo v koren in ga pogrezamo. Postopek ponavljamo, dokler se kopica ne izprazni(vsi elementi so v skladišču) Andrej Grah a.k.a. Burgola

  2. Zaporedje 2 8 3 5 7 0 1 9 2 4 3 7 0 1 uredi s kopico v naraščajočem vrstnem redu. * 2 * 8 3 * 5 7 0 1 * 9 2 4 3 7 0 1 * *=prehod med nivoji Ker hočemo naraščajoč vrstni red, bomo izgradili max. kopico. Andrej Grah a.k.a. Burgola

  3. Našo zaporedje zapisano v kopici. Andrej Grah a.k.a. Burgola

  4. Začnemo urejati kopico na zadnjem mestu. Andrej Grah a.k.a. Burgola

  5. Ker gradimo max kopico gre 7 gor in 0 dol. Andrej Grah a.k.a. Burgola

  6. Se nič ne spremeni Andrej Grah a.k.a. Burgola

  7. 9ka gre gor,5ka na njeno mesto. Andrej Grah a.k.a. Burgola

  8. Zdaj gremo urejat kopice en nivo višje. Andrej Grah a.k.a. Burgola

  9. 7ka gor, 3ka dol. Andrej Grah a.k.a. Burgola

  10. 9ka gor, 8ka dol Andrej Grah a.k.a. Burgola

  11. Sledi še najvišji nivo. Andrej Grah a.k.a. Burgola

  12. 9ka gor, 2ka dol. Andrej Grah a.k.a. Burgola

  13. 2ko se da pogrezati še globlje. Andrej Grah a.k.a. Burgola

  14. Pogrezamo jo tja, kjer je večji sin. (ki mora biti večji od pogrezajočega elementa) Andrej Grah a.k.a. Burgola

  15. Konec. Sedaj smo izgradili kopico. Andrej Grah a.k.a. Burgola

  16. Izgrajeno kopico zapišemo v tabelo: 9 8 7 5 7 3 1 2 2 4 3 0 0 1 Andrej Grah a.k.a. Burgola

  17. 9 8 7 5 7 3 1 2 2 4 3 0 0 1 Koren (9ko) damo v skladišče na zadnje mesto tabele. 8 7 5 7 3 1 2 2 4 3 0 0 1 / 9 Zadnji element kopice (1ko) damo v koren in ga pogrezamo. Dobimo: 8 7 7 5 4 3 1 2 2 1 3 0 0 / 9 Damo 8ko v skladišče in 0lo v koren in jo pogrezamo. Dobimo: 7 5 7 2 4 3 1 0 2 1 3 0 / 8 9 Postopek ponavljamo: 7 5 3 2 4 0 1 0 2 1 3 / 7 8 9 5 4 3 2 3 0 1 0 2 1 / 7 7 8 9 4 3 3 2 1 0 1 0 2 / 5 7 7 8 9 3 2 3 2 1 0 1 0 / 4 5 7 7 8 9 Ko so vsi elementi v skladišču, je algoritma konec. Zaporedje je urejeno. Andrej Grah a.k.a. Burgola

  18. Če pa hočemo narediti padajoč vrstni red, potem pa izgradimo min kopico in spet dajemo korene v skladišče na zadnje mesto v tabeli. Andrej Grah a.k.a. Burgola

More Related