popovIliya

Sort items in ascending order

Mar 20th, 2021
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. def inputL(a,size):
  2.     index=0
  3.     while index < size:
  4.         print("a[",index,"]=")
  5.         elem = float(input())
  6.         a.insert(index,elem)
  7.         index+=1
  8. def Wkl(a,size):
  9.     for i in range(0,size):
  10.         x = float(a[i])
  11.         j = i -1
  12.         while (j >= 0 and x < a[j]):
  13.             a[j+1]=a[j]
  14.             j-=1
  15.         a[j+1]=x
  16.    
  17. def outPut(a):
  18.     for i in range(0,len(a)):
  19.         print("a[",i,"]=",a[i])
  20.        
  21. def main():
  22.     print("Enter the number of elements: ")
  23.     n = int(input())
  24.     a=[]
  25.     inputL(a,n)
  26.     Wkl(a,n)
  27.     outPut(a)
  28.    
  29. main()
Advertisement
Add Comment
Please, Sign In to add comment