Dies ist eine alte Version des Dokuments!
Sortieralgorithmen in Python
Import von Bibliotheken und Hilfsfunktionen
# webtigerjython
from gpanel import *
import random
import time
makeGPanel(0,600,0,400)
# Liste der Zahlen von 0 bis 99 in zufälliger Reihenfolge
zufallsListe = random.sample(range(0,100),100)
setColor("red")
#===============================================================
# Hilfsfunktion drawList, zeichnet ein Diagramm einer Liste
#===============================================================
def drawList(l,sleeptime):
clear()
x = 20
lineWidth(5)
for i in l:
line(x,30,x,i+30)
x = x + 5
time.sleep(sleeptime)
Bubble-Sort Algorithmus
def bubbleSort(list1):
for i in range(len(list1)-1,0,-1): #i läuft rückwärts
for j in range(0,i,1):
drawList(list1,0.01)
if list1[j]>list1[j+1]:
list1[j],list1[j+1] = list1[j+1],list1[j]
bubbleSort(zufallsListe)