Showing posts with label Sorting class 11 python cbse. Show all posts
Showing posts with label Sorting class 11 python cbse. Show all posts

Saturday, 16 March 2019

Sorting class 11 python cbse

SORTING

It refers to arranging element in a specific order ascending or descending 

BUBBLE SORTING

The basic idea is to compare 2 adjoining values and exchange ,then if they are not in proper order.In every pass the heaviest element settles at its appropriate position in the bottom.

BUBBLE SORT

alist=[15,6,13,22,35,2]
print("original list is'' : alist)
        n=len(alist)
for i in range (n):
     for j in range (0,n-j,-1):
           if alist (i)>alist (j+1):
                     alist=(j+1):
print("list after sorting:,alist)

INSERTION SORT

lst=[15,14,2,3,4,5,6,77,88,90]
print("original list is:"lst)
for i in range (1,len(lst)):
          temp=lst[i]
          j=i-1
          while j>0 and temp<lst[j]:
                  lst[j+1]=lst[j]
                   j=j-1
             else:
                  lst[j+1]=temp
print("list after sort is:",lst)