-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.c
More file actions
29 lines (26 loc) · 873 Bytes
/
Copy pathbasic.c
File metadata and controls
29 lines (26 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>
#include "layerkeysort.h"
typedef struct Item { int key; int original; } Item;
static int compare_items(const void *left, const void *right, void *context)
{
const Item *a = (const Item *)left;
const Item *b = (const Item *)right;
(void)context;
return (a->key > b->key) - (a->key < b->key);
}
int main(void)
{
Item values[] = {{2, 0}, {1, 1}, {2, 2}, {1, 3}};
void *items[] = {&values[0], &values[1], &values[2], &values[3]};
size_t index;
LksStatus status = lks_sort(items, 4, compare_items, NULL);
if (status != LKS_STATUS_OK) {
fprintf(stderr, "Sort failed: %s\n", lks_status_string(status));
return 1;
}
for (index = 0; index < 4; ++index) {
const Item *item = (const Item *)items[index];
printf("key=%d original=%d\n", item->key, item->original);
}
return 0;
}