Advertisement
michalkowalczyk

InsertionSort

Dec 3rd, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Mon Nov 19 07:55:01 2018
  4.  
  5. @author: kowamich
  6. """
  7.  
  8. A=[]
  9. from random import randint
  10. for i in range(0,100):
  11.     j=randint(1,100)
  12.     A.append(j)
  13. print(A)    
  14.  
  15. def Insert_sort(A):
  16.     for i in range(1,len(A)):
  17.         klucz = A[i]
  18.         j = i - 1
  19.         while j>=0 and A[j]>klucz:
  20.             A[j + 1] = A[j]
  21.             j = j - 1
  22.         A[j + 1] = klucz
  23.        
  24. Insert_sort(A)
  25. print(A)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement