Hovedinnhold
Kurs: (Informatikk > Enhet 1
Leksjon 5: Sortering ved innsettingInnsetting av sorterings pseudokode
Now that you know how to insert a value into a sorted subarray, you can implement insertion sort:
- Call
insert
to insert the element that starts at index 1 into the sorted subarray in index 0. - Call
insert
to insert the element that starts at index 2 into the sorted subarray in indices 0 through 1. - Call
insert
to insert the element that starts at index 3 into the sorted subarray in indices 0 through 2. - …
- Finally, call
insert
to insert the element that starts at index into the sorted subarray in indices 0 through .
As a reminder, here's the visualization that steps through the algorithm on a deck of cards:
This content is a collaboration of Dartmouth Computer Science professors Thomas Cormen and Devin Balkcom, plus the Khan Academy computing curriculum team. The content is licensed CC-BY-NC-SA.
Ønsker du å delta i samtalen?
Ingen innlegg enda.