BubbleSort
This commit is contained in:
1 parent
59cda27092
commit
4399fea72f
1 file changed
+21
@@ -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))
|
||||
Reference in new issue
Block a user