Write an algorithm to sort an elements using Insertion Sort Algorithm.
Algorithm for Insertion sort steps:
Step 1 : START.
Step 2 : Input N
Step 3 : for I← 0 to N -1 Read A [ I ] ( end of I for loop )
Step 4 : For I ← 1 to N -1 Do
Step 5 : J = I
Step 6 : While ( J > = 1 ) and ( A[ J ] < A [ J -1 ] )
Step 7 : TEMP = A [ J ]
Step 8 : A [ J ] = A [ J - 1 ]
Step 9 : A[ J - 1 ] = TEMP
Step 10 : J = J - 1
[ end of While loop ]
[ end of step I For loop ]
Step 11 : for I ← 0 to N -1
Step 12: Print A [ I ]
Step 13 : Stop.
Thanks
Mukesh Rajput
Post A Comment:
0 comments: