# Stalin sort
# Check if the list is ordered, if it is not, remove the element.
importnumpyasnp# Code
defstalin_sort(list_a):len_a=len(list_a)the_end=Falsei=0j=i+1whilenotthe_end:iflist_a[i]>list_a[j]:list_a.pop(j)len_a=len(list_a)ifi==len_a-1:the_end=Trueelse:i+=1j+=1ifj==len_a:the_end=Truereturnlist_a# Input
n=25# Elements
A=np.random.randint(low=0,high=50,size=n)A=list(A)print(f"Input: {A}")# Output
print(f"Output: {stalin_sort(A)}")
Top comments (1)
AHAHAHAHAHAHAHAHAHAHA