dev #1
@@ -5,6 +5,15 @@
|
|||||||
|
|
||||||
struct list *list_append(struct list *l, int e)
|
struct list *list_append(struct list *l, int e)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
struct list *new_node = malloc(sizeof(struct list));
|
||||||
|
if(!new_node) return NULL;
|
||||||
|
|
||||||
|
new_node->data = e;
|
||||||
|
new_node->next = l;
|
||||||
|
|
||||||
|
return new_node;
|
||||||
|
/*
|
||||||
struct list *tmp = l;
|
struct list *tmp = l;
|
||||||
|
|
||||||
struct list *new_node = calloc(1, sizeof(struct list));
|
struct list *new_node = calloc(1, sizeof(struct list));
|
||||||
@@ -16,7 +25,7 @@ struct list *list_append(struct list *l, int e)
|
|||||||
while (tmp->next != NULL) tmp = tmp->next;
|
while (tmp->next != NULL) tmp = tmp->next;
|
||||||
tmp->next = new_node;
|
tmp->next = new_node;
|
||||||
return l;
|
return l;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
size_t list_count(struct list *l){
|
size_t list_count(struct list *l){
|
||||||
|
|
||||||
@@ -162,26 +171,23 @@ void list_print(struct list *l){
|
|||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
struct list *l = NULL;
|
struct list *l = NULL;
|
||||||
|
|
||||||
l = list_append(l, 42); // l = [42] -> NULL
|
l = list_append(l, 3);
|
||||||
list_print(l);
|
l = list_append(l, 2);
|
||||||
l = list_append(l, 7); // l = [7] -> [42] -> NULL
|
l = list_append(l, 1);
|
||||||
list_print(l);
|
|
||||||
|
|
||||||
// l = [1] -> [2] -> [3]
|
// l = [1] -> [2] -> [3]
|
||||||
list_insert(&l, 1, 99); // l = [1] -> [99] -> [2] -> [3], and list_insert returns 0
|
list_insert(&l, 1, 99); // l = [1] -> [99] -> [2] -> [3], and list_insert returns 0
|
||||||
list_insert(&l, 9, 99); // list unchanged, returns 1
|
list_insert(&l, 9, 99); // list unchanged, returns 1
|
||||||
list_print(l);
|
|
||||||
list_count(NULL); // 0
|
|
||||||
printf("count : %li\n",list_count(l)); // 3
|
|
||||||
|
|
||||||
|
list_print(l);
|
||||||
|
|
||||||
list_destroy(l);
|
list_destroy(l);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user