Home About Contact Privacy Terms Disclaimer
TECHAntena
Last Updated On: June 19, 2016
Editor: Adeeb C

C++ program to sort an array of elements using selection sort

Category: C++,Programing
Tags

Aim:

To write a program to sort an array of elements using selection sort technique.

Algorithm:

SELECTION (A,N)

This algorithm sorts the array A with N elements.

  1.    Repeat Steps 2 and 3 for K = 1, 2, . . . , N-1:

  2.    Call MIN(A, K, N, LOC).

  3.    [Interchange A[K] and A[LOC].]

        Set TEMP : = A[K]; A[K]: = A[LOC] and A[LOC] : = TEMP.

   [End of Step 1 loop]

  1.   Exit.

Program code: