Last change
on this file since 965 was
965,
checked in by campbell, 10 years ago
|
Update some Clight examples.
|
File size:
1016 bytes
|
Line | |
---|
1 | /* Remove memory region for now. */ |
---|
2 | #define __pdata |
---|
3 | |
---|
4 | struct list { |
---|
5 | unsigned char i; |
---|
6 | __pdata struct list *next; |
---|
7 | }; |
---|
8 | |
---|
9 | __pdata struct list l6 = {69, 0}; |
---|
10 | __pdata struct list l5 = {36, &l6}; |
---|
11 | __pdata struct list l4 = {136, &l5}; |
---|
12 | __pdata struct list l3 = {105, &l4}; |
---|
13 | __pdata struct list l2 = {234, &l3}; |
---|
14 | __pdata struct list l1 = {240, &l2}; |
---|
15 | __pdata struct list l0 = {102, &l1}; |
---|
16 | |
---|
17 | void insert(__pdata struct list *element, __pdata struct list **dest) { |
---|
18 | if (*dest == 0 || (*dest)->i >= element->i) { |
---|
19 | element -> next = *dest; |
---|
20 | *dest = element; |
---|
21 | } else |
---|
22 | insert(element, &(*dest)->next); |
---|
23 | } |
---|
24 | |
---|
25 | void sort(__pdata struct list **list) { |
---|
26 | __pdata struct list *current; |
---|
27 | __pdata struct list *next = *list; |
---|
28 | __pdata struct list *result = 0; |
---|
29 | while (next) { |
---|
30 | current = next; |
---|
31 | next = next->next; |
---|
32 | insert (current, &result); |
---|
33 | } |
---|
34 | *list = result; |
---|
35 | } |
---|
36 | |
---|
37 | extern void out(unsigned char c); |
---|
38 | |
---|
39 | int main(void) { |
---|
40 | __pdata struct list *l = &l0; |
---|
41 | |
---|
42 | sort(&l); |
---|
43 | while (l) { |
---|
44 | out(l->i); |
---|
45 | l = l->next; |
---|
46 | } |
---|
47 | |
---|
48 | return 0; |
---|
49 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.