-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubblesort.py
More file actions
executable file
·32 lines (30 loc) · 965 Bytes
/
bubblesort.py
File metadata and controls
executable file
·32 lines (30 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
#-------------------------------------------------------------------------------
# Name: bubblesort
# Purpose:
#
# Author: Christian Wichmann
#
# Created: 14.02.2014
# Copyright: (c) Christian Wichmann 2014
# Licence: GNU GPL
#-------------------------------------------------------------------------------
def main():
zahlen = []
sortiert = False
anzahl = int(input('Anzahl der Zahlen eingeben: '))
for i in range(anzahl):
zahl = input('Zahl eingeben: ')
zahlen.append(zahl)
while not sortiert:
sortiert = True
for i in range(anzahl-1):
if zahlen[i] > zahlen[i+1]:
zwischenspeicher = zahlen[i]
zahlen[i] = zahlen[i+1]
zahlen[i+1] = zwischenspeicher
sortiert = False
for i in range(anzahl):
print(zahlen[i])
if __name__ == '__main__':
main()