mirror of https://github.com/TheAlgorithms/C
Update selection_sort_recursive.c
This commit is contained in:
parent
979b1e3ba7
commit
684b4bc002
|
@ -4,19 +4,19 @@
|
||||||
* @brief [Selection Sort](https://en.wikipedia.org/wiki/Selection_sort)
|
* @brief [Selection Sort](https://en.wikipedia.org/wiki/Selection_sort)
|
||||||
* implementation using recursion.
|
* implementation using recursion.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h> /// for assert
|
#include <assert.h> /// for assert
|
||||||
#include <stdio.h> /// for IO operations
|
#include <stdio.h> /// for IO operations
|
||||||
#include <stdlib.h> /// for dynamic memory allocation
|
#include <stdlib.h> /// for dynamic memory allocation
|
||||||
#include <time.h> /// for random numbers generation
|
#include <time.h> /// for random numbers generation
|
||||||
#include <inttypes.h> /// for uint8_t
|
#include <inttypes.h> /// for uint8_t, int8_t
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Swapped two numbers using pointer
|
* @brief Swapped two numbers using pointer
|
||||||
* @param first pointer of first number
|
* @param first pointer of first number
|
||||||
* @param second pointer of second number
|
* @param second pointer of second number
|
||||||
*/
|
*/
|
||||||
void swap(uint8_t *first, uint8_t *second)
|
void swap(int8_t *first, int8_t *second)
|
||||||
{
|
{
|
||||||
uint8_t temp = *first;
|
uint8_t temp = *first;
|
||||||
*first = *second;
|
*first = *second;
|
||||||
|
@ -29,7 +29,7 @@ void swap(uint8_t *first, uint8_t *second)
|
||||||
* @param size size of array
|
* @param size size of array
|
||||||
* @return min_index index of an element having a minimum value
|
* @return min_index index of an element having a minimum value
|
||||||
*/
|
*/
|
||||||
uint8_t findIndex(const uint8_t *arr, const uint8_t size)
|
uint8_t findIndex(const int8_t *arr, const uint8_t size)
|
||||||
{
|
{
|
||||||
if (size == 1)
|
if (size == 1)
|
||||||
{
|
{
|
||||||
|
@ -53,9 +53,9 @@ uint8_t findIndex(const uint8_t *arr, const uint8_t size)
|
||||||
* @param size size of the array
|
* @param size size of the array
|
||||||
* @returns void
|
* @returns void
|
||||||
*/
|
*/
|
||||||
void selectionSort(uint8_t *arr, const uint8_t size)
|
void selectionSort(int8_t *arr, const uint8_t size)
|
||||||
{
|
{
|
||||||
if (size == 1)
|
if (size <= 1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ void selectionSort(uint8_t *arr, const uint8_t size)
|
||||||
static void test()
|
static void test()
|
||||||
{
|
{
|
||||||
const uint8_t size = 10;
|
const uint8_t size = 10;
|
||||||
uint8_t *arr = (uint8_t *)calloc(size, sizeof(uint8_t));
|
int8_t *arr = (int8_t *)calloc(size, sizeof(int8_t));
|
||||||
|
|
||||||
/* generate size random numbers from 0 to 100 */
|
/* generate size random numbers from 0 to 100 */
|
||||||
for (uint8_t i = 0; i < size; i++)
|
for (uint8_t i = 0; i < size; i++)
|
||||||
|
|
Loading…
Reference in New Issue