数组加链表 = 什么了?数组还是链表
时间:2010-04-12 来源:masonzhang
无聊了写个单环链表 40多行 有空改成个内存池什么的 !目前就这样了
include <stdio.h>
struct list_head {
struct list_head * next;
#ifdef debug
int id;
#endif
};
add_list(struct list_head * head ,struct list_head * new) {
new->next = head ->next;
head->next = new;
};
static struct list_head mem[100] = {0,};
extern int
main(int argc,char * argv[]){
#ifdef debug
mem[0].next = mem;
int i=1;
for(;i<100;i++) {
add_list( mem ,&mem[i]) ;
int j=i;
mem[i].id =j;
}
struct list_head * iteration = mem+4;
printf("start---->");
do {
printf (" %d ",iteration->id) ;
iteration = iteration->next;
iteration = iteration->next;
}while (iteration->next != (mem+4));
printf(" end ---->%d\n",iteration->id);
#endif
return 0;
run results ;
start----> 4 3 2 1 0 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 end ---->5
相关阅读 更多 +