added shakersort algorithm

master
Martin Putzlocher 2022-05-21 13:49:18 +02:00
parent 52ad9376fe
commit 08a915aeb2
3 changed files with 74 additions and 0 deletions

31
algorithmen/shakersort.py Normal file
View File

@ -0,0 +1,31 @@
l = [12,124,1,31,51,4563,76,43,532,7,98,786,63,68,2,15,764,345,2,7,85]
l2 = [1235,999,432,123, 12, 5, 70]
def shakersort(unsorted):
start = 0
end = len(unsorted) - 1 # last possible index of list
exchanged = True
while exchanged and (end >= start):
exchanged = False
# Durchlauf vorwärts
for i in range(start, end, 1):
if unsorted[i] > unsorted[i + 1]:
# Vertausche!
unsorted[i], unsorted[i + 1] = unsorted[i + 1], unsorted[i]
exchanged = True
print(unsorted)
# Durchlauf rückwärts
for j in range(end, start, -1):
if unsorted[j] < unsorted[j - 1]:
# Vertausche!
unsorted[j - 1], unsorted[j] = unsorted[j], unsorted[j - 1]
exchanged = True
print(unsorted)
end = end - 1
start = start + 1
print(str(l2) + " # unsortiert")
shakersort(l2)

6
automata/recog.py Normal file
View File

@ -0,0 +1,6 @@
userin=input("Kennwort eingeben: ")
if userin=="abc":
print("Passwort akzeptiert.")
else:
print("Authentifizierung fehlgeschlagen.")

View File

@ -0,0 +1,37 @@
states={0:"z1",1:"z2",2:"f"}
active=True
activestate=0
intext=""
print("Alphabet: a, b .")
print("Im Endzustand beendet '.'")
while active:
print("Zustand: " +states.get(activestate))
userin = input("Eingabe: ")
if activestate==0:
if userin == "a":
activestate=1
intext=intext+userin
else:
pass
elif activestate==1:
if userin == "b":
activestate=2
intext=intext+userin
else:
pass
elif activestate==2:
if userin == "a":
activestate=1
intext=intext+userin
elif userin == ".":
intext=intext+userin
active=False
else:
pass
print("Eingabe " + intext + " akzeptiert.")