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; }
/*purely designed for printing the "track" stack, since it is the only place to be able to use this function*/ void printStack(Stack *s, void (*printFn)(void *)) { int i; printf("#NumQuestions Responses\n\n"); /*iterate 2 items at a time*/ for (i=0;i<(s->nextFree);i+=2) { printf("#"); printFn(s->data[i]); printf(" "); printFn(s->data[i+1]); printf("\n"); } printf("#---------------------------------\n\n"); }
void stack_print(Stack *s, void(printFn)(void *)) { int i; if (stack_isEmpty(s)) { fprintf(stderr, "Empty Stack\n"); return; } for (i=0;i<s->top;i++) { printFn(s->A[i]); } printf("\n"); }