Coding Paradise. Learn. Ask. Code. REPEAT.

Monday 24 August 2015

Selection sort using C language

PROBLEM STATEMENT

SELECTION SORT


Write a C program to perform selection sort on an array of n elements.
Selection sort algorithm starts by comparing first two elements of an array and swapping if necessary, i.e., if you want to sort the elements of array in ascending order and if the first element is greater than second then, you need to swap the elements but, if the first element is smaller than second, leave the elements as it is. Then, again first element and third element are compared and swapped if necessary. This process goes on until first and last element of an array is compared. This completes the first step of selection sort.

Input Format:
Input consists of n+1 integers. The first integer corresponds to n, the number of elements in the array. The next n integers correspond to the elements in the array.

Output Format:

Print result after every Iteration.



SOLUTION


Here is the solution. If you don't understand any part, feel free to ask in comment.







1 comment:

  1. Selection Sort in C

    Selection sort is simplest way to sort array elements. Selection sort is based of maximum and minimum value. First check minimum value in array list and place it at first position (position 0) of array, next find second smallest element in array list and place this value at second position (position 1) and so on. Same process is repeated until sort all element of an array.

    ReplyDelete

Popular Posts

Powered by Blogger.