blob: 83655cd4af4d8d0b1d88f3e4f40cf32951a54142 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
#include "list.h"
struct List* llist_new()
{
struct List *list=MALLOC( sizeof(struct List) );
list->first = NULL;
list->last = NULL;
list->count = 0;
return list;
}
struct ListNode* llist_newn( void *ptr )
{
struct ListNode *node = MALLOC( sizeof( struct ListNode ) );
node->next = NULL;
node->val = ptr;
return node;
}
int llist_length( struct List *list )
{
int len;
struct ListNode *node=list->first;
for ( len=0; node; node=node->next,len++);
return len;
}
int llist_index( struct List *list, void *ptr )
{
int index;
struct ListNode *node = list->first;
for ( index=0; node; node=node->next, index++)
if ( node->val == ptr )
return index;
return -1;
}
void llist_reverse( struct List **list )
{
//abort(0);
}
void llist_append( struct List *list, void *ptr )
{
//abort(0);
}
void llist_appendn( struct List **list, void *ptr, struct ListNode *node )
{
//abort(0);
}
void* llist_pop( struct List *list )
{
struct ListNode *node = list->last;
struct ListNode *iter = list->first;
if ( node )
{
/*
if ( node->prev != NULL )
{
void *ptr = node->val;
//node = node->prev;
//FREE( node->next );
//node->next = NULL;
//list->last = node;
return ptr;
}
*/
while (iter->next != node)
{
iter = iter->next;
}
void *ptr = node->val;
FREE(iter->next);
iter->next = NULL;
list->last = iter;
return ptr;
}
return NULL;
}
void llist_push( struct List *list, void *ptr )
{
struct ListNode *node = MALLOC( sizeof(struct ListNode) );
node->val = ptr;
node->next = NULL;
if ( list->last )
{
list->last->next = node;
list->last = node;
}
else
{
list->first = node;
list->last = node;
}
}
void llist_free( struct List *list )
{
struct ListNode *node = list->first, *prev;
while ( node != list->last )
{
prev = node;
node = node->next;
if (prev != NULL)
{
FREE( prev->val );
FREE( prev );
}
}
if ( node )
{
if ( node->val )
FREE( node->val );
FREE( node );
}
list->first = NULL;
list->last = NULL;
FREE( list );
list = NULL;
}
void llist_freen( struct ListNode *node )
{
}
|