+ 4
What is bubble sort
2 ответов
+ 4
Here is an implementation of the bubble sort algorithm, in C#:
https://code.sololearn.com/c97IbsV5G44B/#cs
+ 3
bubble sort is an algorithm to sort an array.
explanaition with example:
7 4 9 10 2
bubble sort looks at 7 and 4
since 7 is greater than 4 it swaps them
4 7 9 10 2
now it looks at 7 and 9
9 is greater then 7 so no swaping
now since 9 is the new greatest num we start with 9 now
10 is greater then 9 so we leave 9 and take 10
finally 10 is greater then 2 so wie swap 10 and 2
4 7 9 2 10
now we can either do the same with less instead of greater and go from right to the left or we start again at the beginning and do it again from left to right with greater. This is repeated until nothing changes anymore.
all states for only right to left swaps:
7 4 9 10 2
4 7 9 10 2
4 7 9 2 10
4 7 2 9 10
4 2 7 9 10
2 4 7 9 10