-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fadf614
commit 5dad93b
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2024 LLVM-MOS | ||
// | ||
// Licensed under the Apache License, Version 2.0 with LLVM Exceptions, | ||
// See https://github.com/llvm-mos/llvm-mos-sdk/blob/main/LICENSE for license | ||
// information. | ||
|
||
#undef NDEBUG | ||
#include <assert.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
// Originally from the Public Domain C Library (PDCLib) | ||
|
||
|
||
static int compare(const void *left, const void *right) { | ||
return *((unsigned char *)left) - *((unsigned char *)right); | ||
} | ||
|
||
int main(void) { | ||
char presort[] = {"shreicnyjqpvozxmbt"}; | ||
char sorted1[] = {"bcehijmnopqrstvxyz"}; | ||
char sorted2[] = {"bticjqnyozpvreshxm"}; | ||
char s[19]; | ||
strcpy(s, presort); | ||
qsort(s, 18, 1, compare); | ||
assert(strcmp(s, sorted1) == 0); | ||
strcpy(s, presort); | ||
qsort(s, 9, 2, compare); | ||
assert(strcmp(s, sorted2) == 0); | ||
strcpy(s, presort); | ||
qsort(s, 1, 1, compare); | ||
assert(strcmp(s, presort) == 0); | ||
qsort(s, 100, 0, compare); | ||
assert(strcmp(s, presort) == 0); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exit 0 |