Bubble-sort with Hungarian ("Csángó") folk dance
Why Stack Overflow recommends it
Stack Overflow users link it as a memorable, intuitive way to see how bubble sort swaps adjacent elements, often alongside answers to sorting questions.
Recommended by 5 people across 5 different months, 2011 to 2021.
What it is
A roughly five-minute visualization of the bubble sort algorithm performed by dancers from a Hungarian folk dance ensemble, made at Sapientia University in Romania. It is part of the AlgoRythmics series, which does the same for quick sort, selection sort, merge sort and shell sort.
What people said
Strong rec Legat · 2013-05 · Stack Overflow · on “A program for test sorting algorithms”
Nothing can explain different sorting algorithms better than this Hungarian folk dance group: Bubble-sort [this video] Quick-sort [LINK] Select-sort [LINK] Merge-sort [LINK] Shell-sort [LINK] But if you prefer a bit more formal approach I recommend you this site: [LINK] You can choose different sorting algorithms, number and type of elements to sort and also different data sequences: random, ordered, reversed etc. You can't enter your own data there but I don't think that not using your own sequence of numbers could hinder the ability to understand the concept :)
Recommends graham.reeds · 2015-11 · Stack Overflow · on “Understanding Bubble Sort (Algorithm)”
First, you do seem to be on the right track. Some tips to help you progress further on your journey. Learn the standard template library. There is a function called swap which does exactly what it says on the tin. Secondly use containers. They are less error prone than C-style arrays. Finally here is bubble sort explained via the medium of folk dancing [this video] .
Recommends Erwan Kezzar · 2015-12 · Stack Overflow · on “Group games to teach computer programming (either functional or imperative)”
For inspiration : an example of how physical people can materialize the Bubble Sort algorithm through dance => [this video]
Recommends strikersps · 2019-12 · Stack Overflow · on “unwanted element popping up in int list”
Instead of your implementation of the bubble sort to sort the data of 10 elements, you can use the below implementation. The idea behind is that when you analyze ( which you should [LINK] ) how the bubble-sort algorithm basically sorts the data, you will see a pattern i.e. in each pass of the inner-loop, the largest element (in-case of sorting the data in increasing order) will automatically go to its right location so, you don't need to consider that element again as it is already in its right position. #include <stdio.h> // For basic I/O functions. #include <stdlib.h> // For srand() & rand() functions. #include <time.h> // For time(NULL) functions. #define MAX_ARRAY_SIZE 10 int main(void)
Recommends Cid · 2021-11 · Stack Overflow · on “Bubble sort 2D string array”
if you need help understanding how bubble sort works, I suggest you this video [this video] that shows people dancing while solving it
Cites Trufa · 2011-10 · Stack Overflow · on “Implement ascending sort in a python list”
I hoped you understood why you got the index out of range error. That was one of the problems but now let's examine your code because you have some "conceptual" error, in the sense that you are not fully understanding what the code you made does. This is what your code actually does, and this is how you should think whenever you get errors like this: sample=[23,44,12,1,6,87] temp=0 for i in range(0,len(sample)-1): if sample[i] > sample[i+1]: temp=sample[i] sample[i]=sample[i+1] sample[i+1]=temp First line: Your i will get the values 0,1,2 to 5 (in this case). Second line: It will check whether to members of the list that are next to each other . It will check if the first (from left to right
Cites Markus A. · 2012-12 · Stack Overflow · on “Implementing a Doubly Linked List with Bubble Sort”
In an array or vector you access stored variables via the index, i.e. position in the list of items. In a linked list, you get to a specific item by hopping from one item to the next. Since you are using get(i) in your code, you are obviously using an array or a vector as you are indexing by a position in the list. So, nope... unfortunately you are on an entirely wrong track... once you are getting closer, your code will look more like: boolean changed = true; while (changed) { // keep going until we didn't make any more changes (not // strictly the best condition for bubble sort, but it'll do) a = first; // grab first element b = a.next; // grab next element changed = false; while (b!=last)
Cites rkhb · 2014-10 · Stack Overflow · on “Assembly - bubble sort for sorting string”
1) For bubble sort you need two nested loops. The outer loop resets the start parameters for the inner loop until there is nothing left to swap. 2) You sort characters . That are 8-bit values (bytes). You can't load them directly into a 16-bit register ( mov ax, [bx+si] ). 3) [bx+si] & [bx+si+1] : this is so wrong that I cannot explain the error :-) . Instead of correcting your code I wrote an example "from scratch": following the illustration in [LINK] : .MODEL small .STACK 1000h ; Don't skimp with stack! .DATA Struct0A EQU $ ; Buffer for INT 21h/0Ah (max,got,buf) max db 100 ; Maximum characters buffer can hold (incl. CR (0Dh)) got db 0 ; Number of characters actually read, (excl. CR (0Dh))
Cites Monsieur Ourer · 2016-05 · Stack Overflow · on “Is my Bubble Sort implementation correct?”
You are doing a correct bubble sort ! In your "if" statement, you are correctly swapping two adjacent values if they are not well sorted. And this is the principle of the bubble sort: you repeat this process until your array is correctly sorted. [this video] However you are doing strange things in your code ! As zapl said in the comments you don't need this "n" parameter as you can simply get you array's size in your method. Also prefer using " < length ", " < length - 1 " instead of your <= which are, if you think well, more intuitive public static void bubbleSort(int[] tab) { int n = tab.length ; for (int i = 0; i < n-1; i++) { for (int j = i + 1; j < n ; j++) { if (tab[j] < tab[i]) { int temp
Cites rkhb · 2019-01 · Stack Overflow · on “Sorting a string in alphabetical order using assembly”
You're describing a simple Bubble Sort algorithm according to [LINK] : A ".string" is just an array of characters. The last character has the value 0 to determine the end of the string. A character is coded as an 8-bit-value. So you only need to use the 8-bit registers of the CPU (AL, AH, DL, DH etc.) to handle them. You can use the 32-bit extended registers (EAX, EBX, ECX, EDX etc.), but this complicates things unnecessarily. Bubble Sort needs two nested loops. In this case an endless outer loop that ends when the string is sorted, and an inner loop that handles every character. The following example is very simple. For example, the last - sorted - letter is unnecessarily compared again and