With Bubblesort an array can be sorted.
Input: Array a
Output: sorted Array
Variables: n: size of array, i: current position, h
- for(n=a.size; n>1; n=n-1)
- If(a[i] > a[i+1])
- a[i+1] = a[i]
With Bubblesort an array a can be sorted. It compares two elements e with each other. If they need to be switched this is done. With this algorithm one element is compared with each other element until the comparison is wrong. This is done for all elements.
- Initialize n with the size of the array and I with 0
- for each position n in a and position i in n-1:
- Compare value of a[i] with value of a[i+a]
- Switch the two elements
- Set variable h to value of a[i+1]
- Set value of a[i+a] to value of a[i]
- Set value of a[i] to h