Sorting Algorithms: Selection Sort
Sorting Algorithms: Selection Sort
SELECTION SORT
Selection Sort
(Cards Example)
Initial Configuration
Sorted
Selection Sort
[http://web.ics.purdue.edu/~cs154/lectures/lecture010.htm]
Example:
Selection
Sort
[http://web.ics.purdue.edu/~cs154/lectures/lecture010.htm]
Example: Selection Sort.c
// Selection Sort
#include <stdlib.h>
#define N 6
int main()
{
int a[N]= { 23, 78, 45, 8, 32, 56};
int i,j;
// Sort the array using Selection Sort
int minIndex;
for(i=0; i < N-1; i++)
{
// find the minimum element in the unsorted part of the
array
minIndex=i;
for(j=i+1; j < N; j++)
if(a[j] < a[minIndex])
minIndex = j;