Skip to content

feat: add dutch national flag 3 way sort #941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Update dnf_sort.c
  • Loading branch information
Data-Hero authored Feb 28, 2022
commit 9f590819cebfaeca4ec473c462cf76751cda3fcd
13 changes: 13 additions & 0 deletions sorting/dnf_sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

/**
* @brief Dutch National Flag 3-Way inplace sort algorithm
Expand Down Expand Up @@ -71,6 +72,12 @@ static void test()
dnfSort(arr1, size);
printf("Sorted: \n");
printArray(arr1, size);

int8_t compare1[] = {0, 1, 1, 1, 1, 2};
for (int c = 0; c < size; c++)
{
assert(arr1[c] == compare1[c]);
}
free(arr1);

size = 1;
Expand All @@ -81,6 +88,12 @@ static void test()
dnfSort(arr2, size);
printf("Sorted: \n");
printArray(arr2, size);

int8_t compare2[] = {2};
for (int c = 0; c < size; c++)
{
assert(arr2[c] == compare2[c]);
}
free(arr2);
}

Expand Down