Skip to content
Snippets Groups Projects

Sort

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by DATkachenko

    Алгоритм сортировки(д/з)

    Edited
    snippetfile1.txt 339 B
    from random import randint
    N=5
    A = [randint(1,100) for i in range(N)]
    print("A = ", A)
    def sort(A):	
    	str = range(len(A) - 1)		
    	while True:
    		for j in (str, reversed(str)):
    			swapped = False
    			for i in j:
    				if A[i] > A[i+1]:  
    					A[i], A[i+1] =  A[i+1], A[i]
    					swapped = True
    			if not swapped:
    				return A
    
    B = sort(A)
    print(B)
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment