root/bidlist.c
/* [<][>][^][v][top][bottom][index][help] */
DEFINITIONS
This source file includes following definitions.
- newbidlist
- bidlistadd
- bidlistremove
- bidlistcount
- bidlistget
- bidlistreset
- bidlistnext
- bidlistsetmark
1 /* bidlist.c */
2 #include<bidlist.h>
3 #include<stdio.h>
4 #include<stdlib.h>
5
6 bidlist* newbidlist(void){
7 bidlist* ret = (bidlist*)malloc(sizeof(bidlist));
8 ret->head = NULL;
9 ret->tail = NULL;
10 ret->mark = NULL;
11 ret->count =0;
12 return ret;
13 }
14
15 int bidlistadd(bidlist* blist, void* data){
16 bidnode* newnode = (bidnode*)malloc(sizeof(bidnode));
17 newnode->data = data;
18 newnode->prev = blist->tail;
19 newnode->next = NULL;
20 if(blist->tail != NULL){
21 blist->tail->next = newnode;
22 }
23 blist->tail = newnode;
24 if(blist->head == NULL){
25 blist->head = newnode;
26 }
27 blist->count++;
28 return blist->count;
29 }
30
31 int bidlistremove(bidlist* blist, bidnode* node){
32 bidnode* prev = node->prev;
33 bidnode* next = node->next;
34 if(blist->mark == node){
35 blist->mark = node->next;
36 }
37 if(next!= NULL){
38 next->prev = prev;
39 }else{
40 blist->tail = prev;
41 }
42 if(prev!= NULL){
43 prev->next = next;
44 }else{
45 blist->head = next;
46 }
47 free(node);
48 blist->count--;
49 return blist->count;
50 }
51
52 int bidlistcount(bidlist* blist){
53 return blist->count;
54 }
55
56 bidnode* bidlistget(bidlist* blist, int num){
57 int i;
58 bidnode* point = blist->head;
59 for(i=0;i<num;i++){
60 point = point->next;
61 }
62 return point;
63 }
64
65 void bidlistreset(bidlist* blist){
66 blist->mark = blist-> head;
67 }
68
69 bidnode* bidlistnext(bidlist* blist){
70 bidnode* ret = blist->mark;
71 if(ret != NULL){
72 blist->mark = blist->mark->next;
73 }
74 return ret;
75 }
76
77 bidnode* bidlistsetmark(bidlist* blist, bidnode* node){
78 blist->mark = node;
79 return node;
80 }