source: doc/theses/mike_brooks_MMath/programs/lst-issues-multi-static.run.c @ 75d874a

ADTast-experimental
Last change on this file since 75d874a was 5717495, checked in by Michael Brooks <mlbrooks@…>, 20 months ago

Start of the linked-list chapter.

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[5717495]1#include <sys/queue.h>
2#include <stdio.h>
3
4
5
6int main() {
7
8
9
10
11
12
13
14
15
16
17
18
19
20struct req {
21  int pri, rqr;
22  LIST_ENTRY(req) by_pri;
23  LIST_ENTRY(req) by_rqr;
24};
25
26LIST_HEAD(reql, req);
27
28struct reql reqs_pri_global;
29struct reql reqs_rqr_42;
30struct reql reqs_rqr_17;
31struct reql reqs_rqr_99;
32
33LIST_INIT(&reqs_pri_global);
34LIST_INIT(&reqs_rqr_42);
35LIST_INIT(&reqs_rqr_17);
36LIST_INIT(&reqs_rqr_99);
37
38struct req
39  r42a = {1, 42},
40  r42b = {2, 42},
41  r17a = {2, 17},
42  r17b = {3, 17},
43  r17c = {4, 17},
44  r99a = {3, 99};
45
46LIST_INSERT_HEAD(&reqs_pri_global, &r17c, by_pri);
47LIST_INSERT_HEAD(&reqs_pri_global, &r99a, by_pri);
48LIST_INSERT_HEAD(&reqs_pri_global, &r17b, by_pri);
49LIST_INSERT_HEAD(&reqs_pri_global, &r42b, by_pri);
50LIST_INSERT_HEAD(&reqs_pri_global, &r17a, by_pri);
51LIST_INSERT_HEAD(&reqs_pri_global, &r42a, by_pri);
52
53LIST_INSERT_HEAD(&reqs_rqr_42, &r42b, by_rqr);
54LIST_INSERT_HEAD(&reqs_rqr_42, &r42a, by_rqr);
55
56LIST_INSERT_HEAD(&reqs_rqr_17, &r17c, by_rqr);
57LIST_INSERT_HEAD(&reqs_rqr_17, &r17b, by_rqr);
58LIST_INSERT_HEAD(&reqs_rqr_17, &r17a, by_rqr);
59
60LIST_INSERT_HEAD(&reqs_rqr_99, &r99a, by_rqr);
61
62
63
64
65
66
67
68struct req *cur;
69LIST_FOREACH(cur, &reqs_pri_global, by_pri)
70    printf("{%d %d} ", cur->pri, cur->rqr);
71printf("| ");
72LIST_FOREACH(cur, &reqs_rqr_42, by_rqr)
73    printf("{%d %d} ", cur->pri, cur->rqr);
74printf("| ");
75LIST_FOREACH(cur, &reqs_rqr_17, by_rqr)
76    printf("{%d %d} ", cur->pri, cur->rqr);
77printf("| ");
78LIST_FOREACH(cur, &reqs_rqr_99, by_rqr)
79    printf("{%d %d} ", cur->pri, cur->rqr);
80printf("\n");
81
82}
Note: See TracBrowser for help on using the repository browser.