int main(int argc, char const *argv[]) { // creating a new list dll_t *list = dll_create(); dll_registerCompareFn(list, compareFn); dll_registerFreeFn(list, freeFn); dll_registerPrintFn(list, printFn); // ask for the number of persons to enter puts("How many persons do you like to enter?"); char input[sizeof(stdin)]; fgets(input, sizeof(stdin), stdin); int x; sscanf(input, "%d", &x); // ask for person data for x times int i; for(i = 0; i < x; i++) { dll_pushTail(list, askPersonData() ); } // print data dll_print(list); puts(""); // reverse the list puts("reverse"); dll_reverse(list); // use dll iterator functions in a for loop to print the reversed list for(dll_head(list); dll_hasNext(list); dll_next(list)) { printFn(list->curr->data); } puts("sort"); dll_sort(list); // use dll iterator functions in a while loop to print the sorted list dll_head(list); while(dll_hasNext(list)) { printFn(list->curr->data); dll_next(list); } printf("List size: %ld\n", dll_size(list)); // empty the whole list dll_clear(list); return 0; }
int main(int argc, char *argv[]) { dllist_t *list = (dllist_t*) malloc(sizeof(dllist_t)); dll_init(list); dll_print(list); dll_add(list, 12); dll_print(list); dll_add(list, 12); dll_add(list, 13); dll_add(list, 14); dll_print(list); dll_remove(list, 12); dll_print(list); dll_delete(list); free(list); return 0; }
int main(void) { A* a = malloc(sizeof(A)), *b = malloc(sizeof(A)), *c = NULL; List* l = list_init(); Stack* s = stack_init(); Queue* q = queue_init(); DoubleLinkedList* d = dll_init(); printf("a: %d\nB: %d\nc: %d\n", (int)a, (int)b, (int)c); a->a1 = 1; a->a2 = 'c'; b->a1 = 2; b->a2 = 'a'; printf("\n=== LIST TEST ===\n"); list_add(l, a, 0); list_append(l, b); list_remove(l, 0); list_print(l); c = list_get(l, 0); printf("c: %d\n", (int)c); list_delete(l); printf("\n=== STACK TEST ===\n"); stack_push(s, b); stack_push(s, a); stack_pop(s); stack_print(s); c = stack_peek(s); printf("c: %d\n", (int)c); stack_delete(s); printf("\n=== QUEUE TEST ===\n"); queue_push(q, a); queue_push(q, b); queue_pop(q); queue_print(q); c = queue_peek(q); printf("c: %d\n", (int)c); queue_delete(q); printf("\n=== DOUBLE LINKED LIST TEST ===\n"); dll_add(d, b, 0); dll_prepend(d, a); dll_remove(d, 1); dll_print(d); c = dll_get(d, 0); printf("c: %d\n", (int)c); dll_delete(d); free(a); free(b); return 0; }