3 ms·
What extra code? I've got a struct definition, a print_list function, cons, and a really dumb testing driver that builds the list [1 2 3], reversing and printin
by swolchok 16y ago
What extra code? I've got a struct definition, a print_list function, cons, and a really dumb testing driver that builds the list [1 2 3], reversing and printing it a few times throughout its construction. The line count of all that [EDIT: I meant "everything except the testing driver"] is about equal to the line count of my reverse.
- jast 16y agoThat extra code :-) First I wrote everything to manipulate a linked list and test it and then I wrote the reverse function. Since I wrote a insert at front function, the reverse function is small. I must add that I am not a fast typer.
- cabalamat 16y agoHow long is your reverse? Mine is 14 lines (see below), and I doubt I could code the rest in that length. struct LinkedList { LinkedList* next; int data; } void reverseLL(linkedList* ll){ if (ll==NULL) return NULL; LinkedList* newList; prev = NULL; for (;;) { newList = malloc(LinkedList); newList->data = ll->data; newList->next = prev; if (ll->next==NULL) break; prev = newList; ll = ll->next; } return newList; }
- deleted 16y ago[deleted]
- swolchok 16y agohttp://scott.wolchok.org/listrev.c http://scott.wolchok.org/listrev.c is what I was satisfied with yesterday. I seem to have exaggerated slightly about the non-driver code being the same length as the reverse, but it's close.