name | version |
---|---|
Python | 3.7.1 |
The source code is as follows.
src = [3, 5, 1, 8, 5, 9]
print(src)
for i in range(len(src)-1):
for j in range(len(src)-1-i):
if src[j] > src[j+1]:
tmp = src[j]
src[j] = src[j+1]
src[j+1] = tmp
print(src)
The execution result is as follows.
[3, 5, 1, 8, 5, 9]
[1, 3, 5, 5, 8, 9]
Thank you for reading until the end. Let's meet again.
Recommended Posts