49 ms·
How 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;
by cabalamat 16y ago
How 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.