We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9d344a2 commit f334ac1Copy full SHA for f334ac1
1 file changed
Level_03/Aufgaben/bubblesort.py
@@ -0,0 +1,25 @@
1
+#!/usr/bin/env python3
2
+import random
3
+
4
+def get_random_list(n: int) -> list:
5
+ result = list(range(n))
6
+ random.shuffle(result)
7
+ return result
8
9
+n = int(input("Länge der Liste: "))
10
+unsorted_list = get_random_list(n)
11
12
+# Bitte die Zeilen 1-12 unverändert lassen
13
14
+def bubblesort(unsorted_list):
15
+ changed = True
16
+ while changed:
17
+ changed = False
18
+ for i in range(len(unsorted_list)-1):
19
+ if unsorted_list[i] > unsorted_list[i+1]:
20
+ unsorted_list[i], unsorted_list[i+1] = unsorted_list[i+1], unsorted_list[i]
21
22
23
+print(unsorted_list)
24
+bubblesort(unsorted_list)
25
0 commit comments