BubbleSort

This commit is contained in:
unknown committed 2026-04-28 08:25:45 +02:00
1 parent 59cda27092
commit 4399fea72f
1 file changed
+21
+21
View File
@@ -0,0 +1,21 @@
import random
import time
zahlen = []
anzahlElemente = 20
for i in range(anzahlElemente):
zahlen.append(random.randint(1, anzahlElemente-1))
print(zahlen)
start = time.time()
for k in range(1, anzahlElemente):
for i in range(anzahlElemente -1):
if zahlen[i] > zahlen[i+1]:
zahlen[i], zahlen[i+1] = zahlen[i+1], zahlen[i]
stopp = time.time()
print(zahlen)
print()
print('{0:5.3f}s'.format(stopp-start))