source: src/Clight/test/insertsort.c @ 2177

Last change on this file since 2177 was 965, checked in by campbell, 9 years ago

Update some Clight examples.

File size: 1016 bytes
Line 
1/* Remove memory region for now. */
2#define __pdata
3
4struct 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
17void 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
25void 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
37extern void out(unsigned char c);
38
39int 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.