From c6bc541ab58363d783e60a007e80e9bf9e231fda Mon Sep 17 00:00:00 2001 From: garhve Date: Mon, 5 Dec 2022 19:43:39 +0800 Subject: initialize --- .../blist/bhlist.c" | 76 ++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 "c/dataStructure/\347\272\277\346\200\247\350\241\250/\347\272\277\346\200\247\351\223\276\350\241\250/blist/bhlist.c" (limited to 'c/dataStructure/线性表/线性链表/blist/bhlist.c') diff --git "a/c/dataStructure/\347\272\277\346\200\247\350\241\250/\347\272\277\346\200\247\351\223\276\350\241\250/blist/bhlist.c" "b/c/dataStructure/\347\272\277\346\200\247\350\241\250/\347\272\277\346\200\247\351\223\276\350\241\250/blist/bhlist.c" new file mode 100755 index 0000000..1c0dbc8 --- /dev/null +++ "b/c/dataStructure/\347\272\277\346\200\247\350\241\250/\347\272\277\346\200\247\351\223\276\350\241\250/blist/bhlist.c" @@ -0,0 +1,76 @@ +// Implement +#include "bhlist.h" + +void InitList (Blist * L) +{ + *L = NULL; +} + +bool AddElem(Blist * L, int e) +{ + Blist scan = *L; + BNode * new = (BNode *) malloc (sizeof(BNode)); + + if (!new) + { + fprintf(stderr,"Memory error!\n"); + return false; + } + + new->data = e; + new->next = NULL; + + if (!scan) + { + new->prior = NULL; + *L = new; + } + + else + { + while (scan->next) + scan = scan->next; + new->prior = scan; + scan->next = new; + } + + return true; +} + +void DestroyList (Blist * L) +{ + Blist t1 = *L; + Blist t2; + + while (t1) + { + t2 = t1->next; + free(t1); + t1 = t2; + } +} + +void TraverseList(Blist * L) +{ + Blist tmp = *L; + Blist ta,tb; + + while (tmp) + { + printf("Element is %d\n",tmp->data); + tb = tmp->prior; + ta = tmp->next; + if (tb) + printf("It's prior element is %d, ",tb->data); + else + printf("No element before it, "); + + if (ta) + printf("and it's next element is %d!\n",ta->data); + else + printf("No element after it!\n"); + + tmp = tmp->next; + } + puts("Traverse DONE!"); +} \ No newline at end of file -- cgit v1.2.3-70-g09d2