I use python 3.10. Once I tried to write bubble sort, but it works in unexpected way-it fills the array with copies of some of it's elements.
For example, array, I wanted to sort: [43, 33, 68, 80, 90, 15, 21, 17, 21, 48]
"Sorted" array: [15, 15, 15, 15, 15, 15, 17, 17, 21, 48]
Here is the code:
for i in range(N - 1): # N-number of elements
for j in range(N - i - 1):
if a[j] > a[j + 1]:
a[j] = a[j + 1]
a[j + 1] = a[j]
Please help me find the error here...