Insert-sort with Romanian folk dance
Why Stack Overflow recommends it
Stack Overflow users link it as a memorable visual explanation of how insertion sort works when answering or asking about sorting code.
Recommended by 1 people across 1 different months, 2011 to 2014.
What it is
A 4-minute visualization of the insertion sort algorithm performed as a Romanian folk dance, made at Sapientia University in Tirgu Mures with the Maros Art Ensemble. Dancers act out the comparisons and shifts of the algorithm, and it is part of the AlgoRythmics series of sorting dances.
What people said
Recommends Andrei B · 2014-02 · Stack Overflow · on “sort as string enters array alphabetical java”
Your teacher probably expects from you to implement the InsertSort algoritm. See this sources for more details: [this video] [LINK] It should look something like: while (in.hasNextLine()) { nextName = in.next(); nextNumber = in.nextInt(); for(i = size; i > 0; --i) { if ( people[i - 1].getName().compareTo(nextName) <= 0 ) { break; } people[i] = people[i-1]; } people[i] = new Person(nextName, nextNumber); size++; in.nextLine(); }
Cites thom · 2011-04 · Stack Overflow · on “PHP Insert Sort function performance”
I'm studying about sorting and I've made a insert sort function ( video [this video] ): <?php set_time_limit(null); function insertSort(array &$array) { $array_size = count($array); $tmp = null; for ($i = 0; $i < $array_size; $i++) { $j = $i + 1; if ($j == $array_size) { break; } while ($array[$j] < $array[$i]) { $tmp = $array[$i]; $array[$i] = $array[$j]; $array[$j] = $tmp; if ($i > 0) { $i--; } $j--; } } } $array = range(0, 100); shuffle($array);//array(3, 0, 1, 8, 7, 2, 5, 4, 9, 6); $time_start = microtime(true); insertSort($array); $time_end = microtime(true); echo ($time_end - $time_start); ?> I've got the following results with microtime: 10000 integers - 69.174551010132 5000 integers - 16.
Cites Damian Schenkelman · 2012-10 · Stack Overflow · on “How does Python insertion sort work?”
If we consider an array from left to right [LeftMost, ..., RightMost], an insertion sort performs the following procedure for each item: Get the current value i. Get the value j (where j = i-1 in the first iteration, or basically the first element to the left of i). In the first iteration of the while array[i] and array[j] are to consecutive elements. For example, if array = [... 60, 100, 50, ...], and array[i] is 50, then array[j] is 100. If the previous value is greater than the current one, then it swaps the two values. Basically if you had something like [..., 60, 100, 50, ...] before this operation takes place, you will end up with [..., 60, 50, 100, ...]. The idea is that you move each