/**
Program Name: Selection Sort
Description: This Program sort a given array elements, using Selection
Sort Algorithm
Author: Tauqirul Haque
*/
#include <conio.h>
#include <stdio.h>
#define MAX 5
void selectionSort(int *, int );
void display(int *);
void main()
{
int array[MAX] = { 35,56,23,11,46 };
printf("\nThe Array Before Sortint .... \n");
display(array);
selectionSort(array,MAX);
printf("\n\nThe Array After Sorting .. \n");
display(array);
}
void selectionSort(int *array, int array_size)
{
int i, j;
int min, temp;
for (i = 0; i < array_size-1; i++)
{
min = i;
for (j = i+1; j < array_size; j++)
{
if (array[j] < array[min])
min = j;
}
temp = array[i];
array[i] = array[min];
array[min] = temp;
}
}
void display(int *array)
{
int i;
printf("\n");
for(i=0;i<MAX;i++)
{
printf("%5d",array[i]);
}
printf("\n");
}
Program Name: Selection Sort
Description: This Program sort a given array elements, using Selection
Sort Algorithm
Author: Tauqirul Haque
*/
#include <conio.h>
#include <stdio.h>
#define MAX 5
void selectionSort(int *, int );
void display(int *);
void main()
{
int array[MAX] = { 35,56,23,11,46 };
printf("\nThe Array Before Sortint .... \n");
display(array);
selectionSort(array,MAX);
printf("\n\nThe Array After Sorting .. \n");
display(array);
}
void selectionSort(int *array, int array_size)
{
int i, j;
int min, temp;
for (i = 0; i < array_size-1; i++)
{
min = i;
for (j = i+1; j < array_size; j++)
{
if (array[j] < array[min])
min = j;
}
temp = array[i];
array[i] = array[min];
array[min] = temp;
}
}
void display(int *array)
{
int i;
printf("\n");
for(i=0;i<MAX;i++)
{
printf("%5d",array[i]);
}
printf("\n");
}
Comments