os_kernel_lab/related_info/lab0/lab0_ex4.c

28 lines
561 B
C
Raw Normal View History

2015-03-06 11:53:47 +08:00
#include <stdio.h>
#include <stdlib.h>
#include "list.h"
struct entry {
list_entry_t node;
int num;
};
int main() {
struct entry head;
list_entry_t* p = &head.node;
list_init(p);
head.num = 0;
int i;
for (i = 1; i != 10; i ++) {
struct entry * e = (struct entry *)malloc(sizeof(struct entry));
e->num = i;
list_add(p, &(e->node));
p = list_next(p);
}
//reverse list all node
while ((p = list_prev(p)) != &head.node)
printf("%d\n", ((struct entry *)p)->num);
return 0;
}