-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbh-test.c
More file actions
55 lines (39 loc) · 932 Bytes
/
bh-test.c
File metadata and controls
55 lines (39 loc) · 932 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* Simple Binary Heap with Wait Queue
*
* Copyright (c) 2015-2023 Alexei A. Smekalkine
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <stdio.h>
#include <data/bh.h>
static int gt (const void *a, const void *b)
{
return a > b;
}
static const int test[] = {
1, 2, 3, 17, 53, 413, 3, 42, 15, 32, 3, 8, 9, 11, 112, 327, 0
};
int main (int argc, char *argv[])
{
struct bh o;
const int *p, *e;
bh_init (&o, gt);
printf ("push");
for (p = test; *p != 0; ++p)
if (bh_push (&o, NULL + *p, 0))
printf (" %d", *p);
printf ("\ntop = %ld\npop", (long) bh_top (&o));
while ((e = bh_pop (&o)) != NULL)
printf (" %ld", (long) e);
printf ("\npush");
for (p = test; *p != 0; ++p)
if (bh_push (&o, NULL + *p, 0))
printf (" %d", *p);
printf ("\ntop = %ld\npop", (long) bh_top (&o));
while ((e = bh_pop (&o)) != NULL)
printf (" %ld", (long) e);
printf ("\n");
bh_fini (&o, NULL);
return 0;
}