Selection sort algorithm implementation.
More...
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
|
| void | swap (int *first, int *second) |
| | Swapped two numbers using pointer. More...
|
| |
| void | selectionSort (int *arr, int size) |
| | Selection sort algorithm implements. More...
|
| |
| static void | test () |
| | Test function. More...
|
| |
|
int | main (int argc, const char *argv[]) |
| | Driver Code.
|
| |
Selection sort algorithm implementation.
◆ selectionSort()
| void selectionSort |
( |
int * |
arr, |
|
|
int |
size |
|
) |
| |
Selection sort algorithm implements.
- Parameters
-
| arr | array to be sorted |
| size | size of array |
30 for (
int i = 0; i < size - 1; i++)
33 for (
int j = i + 1; j < size; j++)
35 if (arr[min_index] > arr[j])
42 swap(arr + i, arr + min_index);
◆ swap()
| void swap |
( |
int * |
first, |
|
|
int * |
second |
|
) |
| |
Swapped two numbers using pointer.
- Parameters
-
| first | first pointer of first number |
| second | second pointer of second number |
◆ test()
| static void test |
( |
void |
| ) |
|
|
static |
Test function.
- Returns
- None
52 const int size = rand() % 500;
53 int *arr = (
int *)calloc(size,
sizeof(
int));
56 for (
int i = 0; i < size; i++)
58 arr[i] = (rand() % 100) - 50;
61 for (
int i = 0; i < size - 1; ++i)
63 assert(arr[i] <= arr[i + 1]);