First Upload
This commit is contained in:
59
24 - SelectSearch/quickselect.c
Normal file
59
24 - SelectSearch/quickselect.c
Normal file
@@ -0,0 +1,59 @@
|
||||
#include "General.h"
|
||||
|
||||
|
||||
void CopyPointers(int * start_dest_index, int * start_src_index, unsigned int length)
|
||||
{
|
||||
unsigned int counter;
|
||||
for (counter = ZERO; counter < length; counter++)
|
||||
{
|
||||
*(start_dest_index++) = *(start_src_index++);
|
||||
}
|
||||
}
|
||||
|
||||
int GetHaziyon(int * ptr_arr, unsigned int length)
|
||||
{
|
||||
int haziyon;
|
||||
if (length % TWO)
|
||||
{
|
||||
haziyon = *(ptr_arr + (length / TWO) + ONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
haziyon = (*(ptr_arr + (length / TWO)) + *(ptr_arr + (length / TWO) + ONE)) / TWO;
|
||||
}
|
||||
|
||||
return (haziyon);
|
||||
}
|
||||
|
||||
unsigned int SortFiveValuesAndGetHaziyon(int * ptr_arr, unsigned int length, int ** ptr_haziyons, void sort(int *, unsigned int))
|
||||
{
|
||||
int haziyon;
|
||||
unsigned int length_arr_haziyons = ONE;
|
||||
if (length > FIVE)
|
||||
{
|
||||
sort(ptr_arr + length - FIVE, FIVE);
|
||||
haziyon = GetHaziyon(ptr_arr + length - FIVE, FIVE);
|
||||
length_arr_haziyons = SortFiveValuesAndGetHaziyon(ptr_arr, length - FIVE, ptr_haziyons, sort) + ONE;
|
||||
*ptr_haziyons = (int *)realloc(*ptr_haziyons, sizeof(int) * length_arr_haziyons);
|
||||
}
|
||||
else
|
||||
{
|
||||
sort(ptr_arr, length);
|
||||
haziyon = GetHaziyon(ptr_arr, length);
|
||||
*ptr_haziyons = (int *)malloc(sizeof(int));
|
||||
}
|
||||
*(ptr_haziyons + length_arr_haziyons - ONE) = haziyon;
|
||||
|
||||
return (length_arr_haziyons);
|
||||
}
|
||||
|
||||
int * Select(int * ptr_arr, unsigned int length, int k)
|
||||
{
|
||||
unsigned int new_length;
|
||||
int * temp_arr;
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user