Algorithms_in_C 1.0.0
Set of algorithms implemented in C.
Loading...
Searching...
No Matches
insertion_sort_recursive.c File Reference

Insertion sort algorithm implementation. More...

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
Include dependency graph for insertion_sort_recursive.c:

Functions

void RecursionInsertionSort (int *arr, int size)
 Insertion sort algorithm implements using Recursion.
 
static void test ()
 Test function.
 
int main (int argc, const char *argv[])
 Main function.
 

Detailed Description

Insertion sort algorithm implementation.

Function Documentation

◆ main()

int main ( int  argc,
const char *  argv[] 
)

Main function.

Returns
integer 0
66{
67 /* Intializes random number generator */
68 srand(time(NULL));
69 test();
70 return 0;
71}
static void test()
Test function.
Definition insertion_sort_recursive.c:44
Here is the call graph for this function:

◆ test()

static void test ( void  )
static

Test function.

Returns
None
45{
46 const int size = rand() % 500; /* random array size */
47 int *arr = (int *)calloc(size, sizeof(int));
48
49 /* generate size random numbers from -50 to 49 */
50 for (int i = 0; i < size; i++)
51 {
52 arr[i] = (rand() % 100) - 50;/* signed random numbers */
53 }
54 RecursionInsertionSort(arr, size);
55 for (int i = 0; i < size ; ++i)
56 {
57 assert(arr[i] <= arr[i + 1]);
58 }
59 free(arr);
60}
void RecursionInsertionSort(int *arr, int size)
Insertion sort algorithm implements using Recursion.
Definition insertion_sort_recursive.c:20
#define free(ptr)
This macro replace the standard free function with free_dbg.
Definition malloc_dbg.h:26
#define calloc(elemCount, elemSize)
This macro replace the standard calloc function with calloc_dbg.
Definition malloc_dbg.h:22
Here is the call graph for this function: