Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tauscht die Array-Werte
- def swap(arr, pos1, pos2):
- tmp = arr[pos1]
- arr[pos1] = arr[pos2]
- arr[pos2] = tmp
- return arr
- # Variante 1
- arr = [57,19,48,26,25,90,73,12,34,29,29,29,200,29,212,73,293,2,203,284,39,123]
- pos = 0
- max = len(arr)-1
- while (pos < max):
- if (arr[pos] > arr[pos+1]):
- arr = swap(arr, pos, pos+1)
- pos += 1
- if pos == max:
- pos = 0
- max -= 1
- print('Fertig:')
- print(arr)
- # Variante 2
- arr = [7, 3, 5, 9, 4, 1]
- for x in range(len(arr)):
- for i in range(len(arr)-x-1):
- if arr[i] > arr[i+1]:
- arr = swap(arr, i, i+1)
- print('Fertig:')
- print(arr)
Add Comment
Please, Sign In to add comment