Write an algorithm to sort an elements using Bubble Sort Algorithm.
Algorithm for bubble sort steps:
Step 1 : START
Step 2 : Input N
Step 3 : for I← 0 to N -1
Step 4 : Read ( A [ I ] )
( end of for loop )
Step 5 : for I← 1 to N -1
Step 6 : for J ← 0 to N –I - 1
Step 7 : If (A[ J ] > A [ J +1] )
Temp ← A [ J ]
A [ J ] ← A [ J + 1 ]
A [ J +1 ] ← Temp
[ end of if ]
[ end of J loop ]
[ end of I loop ]
Step 8 : for J ← 0 to N -1
Print A [ J ]
Step 9 : Stop.
Thanks
Mukesh Rajput
Post A Comment:
0 comments: