|
|
|
@ -22,7 +22,7 @@ int list_length(list_node_t * list) {
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool list_empty(list_node_t *list) {
|
|
|
|
|
bool list_empty(list_node_t * list) {
|
|
|
|
|
return (list == NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -37,7 +37,7 @@ void list_print(list_node_t * list) {
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void list_add(list_node_t *list, list_node_t *item) {
|
|
|
|
|
void list_add(list_node_t * list, list_node_t * item) {
|
|
|
|
|
list_node_t *cur;
|
|
|
|
|
|
|
|
|
|
cur = list;
|
|
|
|
@ -49,16 +49,16 @@ void list_add(list_node_t *list, list_node_t *item) {
|
|
|
|
|
cur->next = item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void list_remove(list_node_t *list, list_node_t *item) {
|
|
|
|
|
void list_remove(list_node_t * list, list_node_t * item) {
|
|
|
|
|
list_node_t *cur;
|
|
|
|
|
|
|
|
|
|
cur = list,
|
|
|
|
|
cur = list;
|
|
|
|
|
assert(cur != NULL);
|
|
|
|
|
|
|
|
|
|
while (cur->next != NULL) {
|
|
|
|
|
if (cur->next->data == item->data) {
|
|
|
|
|
cur->next = cur->next->next;
|
|
|
|
|
return; /* just the first */
|
|
|
|
|
return; /* just the first */
|
|
|
|
|
}
|
|
|
|
|
cur = cur->next;
|
|
|
|
|
}
|
|
|
|
@ -89,7 +89,7 @@ int main(int argc, char *argv[]) {
|
|
|
|
|
|
|
|
|
|
// append more
|
|
|
|
|
const int howmany = 100;
|
|
|
|
|
for(int i = 0; i < howmany; i++) {
|
|
|
|
|
for (int i = 0; i < howmany; i++) {
|
|
|
|
|
list_node_t *newnode = malloc(sizeof(list_node_t));
|
|
|
|
|
newnode->data = i;
|
|
|
|
|
|
|
|
|
|