Write an algorithm to sort an elements using Selection Sort Algorithm.

Algorithm for selection sort steps:
Step 1 : START
Step 2 : Input N
Step 3 : for I← 0 to N -1
Step 4 : Read A [ I ]
Step 5 : for I ← 0 to N -2
Step 6 : S ← A [ I]
Step 7 : POS ← I
Step 8 : for J ← I + 1 to N -1
Step 9 : If ( A[ J] < S )
Step 10 : S ← A [ J ]

Step 11 : POS ← J
[ end of if ]
[ end of J for loop ]
Step 12 : A [ POS ] ← a[ I ]
Step 14 : A[ I ] ← S
[end of I for loop ]
Step 15: for I = 0 to N – 1
Step 16: Print A[ I ]
Step 17: Stop


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: