-4
こんにちは、バブルソートしようとしています。擬似コードでこのバブルソートを行う方法
これは特別なタスクの一部ですが、私はプログラムのPythonコードに固執しています。私はプログラムをやろうとしましたが、バブルをソートする代わりに無限ループを実行します。
こんにちは、バブルソートしようとしています。擬似コードでこのバブルソートを行う方法
これは特別なタスクの一部ですが、私はプログラムのPythonコードに固執しています。私はプログラムをやろうとしましたが、バブルをソートする代わりに無限ループを実行します。
あなたの答えはPythonコードです。
#This is the list that will be sorted.
list1 = [87,4,23,100,29,7,16,56,576,45,23,34,546,7,8,9,4,3,567,1,484,3274,73]
#This keeps the while loop going.
change = 1
#This holds the list reference of the value.
a = 0
#This holds the actual value in the list that is compared.
b = 0
#This holds the next value in the list.
c = 0
#This keeps the program going while it is still sorting.
while change == 1:
#This defines b.
b = list1[a]
#This defines c.
c = list1[a + 1]
#This checks a is bigger than c.
if b > c:
#This reassigns the values in the right places.
list1[a+1] = b
list1[a] = c
#Registers a change.
g = 0
#This checks if a can be increased and still be in the list.
if a + 2 < len(list1):
#This makes a larger to test different elements.
a = a + 1
#If none prior are done then the program does this.
else:
#This resets a to go through the list again.
a = 0
#This records that there has been no change.
g = g + 1
#This makes it stop.
if g == len(list1):
change = 0
print(list1)
ありがとう@Blueray Evans –
あなたのコードをどうぞ! –
これをチェックして、バブルソートアルゴリズムの作成方法を説明します。http://interactivepython.org/runestone/static/pythonds/SortSearch/TheBubbleSort.html – Paddy