Update selection_sort_recursive.c

This commit is contained in:
DhruvPasricha 2021-03-01 22:06:40 +05:30 committed by GitHub
parent 979b1e3ba7
commit 684b4bc002
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 7 deletions

View File

@ -4,19 +4,19 @@
* @brief [Selection Sort](https://en.wikipedia.org/wiki/Selection_sort)
* implementation using recursion.
*/
#include <assert.h> /// for assert
#include <stdio.h> /// for IO operations
#include <stdlib.h> /// for dynamic memory allocation
#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
* @param first pointer of first 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;
*first = *second;
@ -29,7 +29,7 @@ void swap(uint8_t *first, uint8_t *second)
* @param size size of array
* @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)
{
@ -53,9 +53,9 @@ uint8_t findIndex(const uint8_t *arr, const uint8_t size)
* @param size size of the array
* @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;
}
@ -80,7 +80,7 @@ void selectionSort(uint8_t *arr, const uint8_t size)
static void test()
{
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 */
for (uint8_t i = 0; i < size; i++)