Example #1
0
int main(int argc, char** argv) {
	LinkedList tmp_ll = init_linkedlist();
	tmp_ll = add_head(tmp_ll, 14);
	tmp_ll = add_head(tmp_ll, 17);
	print_linkedlist(tmp_ll);

    /* tmp_ll = add_head(tmp_ll, 13);
    tmp_ll = add_head(tmp_ll, 14);
    tmp_ll = remove_head(tmp_ll);
    tmp_ll = add_tail(tmp_ll, 17);
    tmp_ll = remove_tail(tmp_ll);*/
    tmp_ll = empty_linkedlist(tmp_ll);

    print_linkedlist(tmp_ll);

    return EXIT_SUCCESS;
}
Example #2
0
void test_linked_lists()
{
    linked_list list;
    ll_create_list(&list);    

    for (int i = 0; i < 10; i++)
    {
        printf("Writing data. Size: %d\n", list->size);
        point *p = malloc(sizeof(point));
        p->x = 2 * i;
        p->y = 3 * i;
        printf("Size of list: %d\n", sizeof(list));
        list_node node;
        node.data = p;
        ll_add_node(&list, node, TAIL);
    }

    print_linkedlist(list, "\n", print_ll_node);
    printf("\n\n");
    
    point p1;
    p1.x = 100000;
    p1.y = 150000;

    // point p2;
    // p2.x = 20;
    // p2.y = 40;
    
    list_node node;    
    
    node.data = &p1;
    ll_add_node(&list, node, 5);
    // ll_add_node(&list, node, 20);

    ll_remove_node(&list, 1);

    print_linkedlist(list, "\n", print_ll_node);

    for (int i = 0; i < 10; i++)
    {
        ll_remove_node(&list, HEAD);
    }

    ll_remove_node(&list, HEAD);

    print_linkedlist(list, "\n", print_ll_node);

    // node.data = &p2;
    // ll_add_node(list, node);
    // ll_add_node(list, node);
    // ll_add_node(list, node);
    // ll_add_node(list, node);

    // list_node tmp = ll_get_node(list, 2);
    // list_node tmp = *(list->head);

    // void *data = tmp.data;    
    // point *p_tmp = (point *)data;
    // printf("%d %d\n", p_tmp->x, p_tmp->y);
    printf("Size: %d\n", list->size);

}