def quicksort(mas):
if mas:
mid = mas[0]
menshe = [i for i in mas[1:] if i < mid]
bolshe = [i for i in mas[1:] if i >= mid]
return quicksort(menshe) + [mid] + quicksort(bolshe)
else:
return mas
n = int(input())
mas = input().split()
print(*quicksort(mas))
es auf einigen Tests nicht besteht, zum BeispielQuicksort Python Sortier Probleme
input:
3
8 21 22
output:
21 22 8
wie Sie den Code zu verbessern?
Ihre Eingabe 'mas' Strings enthält, nicht ganze Zahlen. Daher haben Sie eine lexikografische Sortierung: '2' steht vor' 8'. – MrT
Hinweis: Ihre 'n'-Variable wird nicht verwendet. Vielleicht 'mas = input(). Split() [: n] '? Oder 'mas = [int (Element) für Element in Eingabe(). Split() [: n]]', um auch die Lösung zu enthalten? – CristiFati