Warning! Answer below. If you want to work on it yourself, don't read it!
Okay, so here's one of the two clever solutions:
Starting at the front (head) of the list, you reverse all of the pointers. So, for example, in the first iteration of this procedure, you'd buffer the head pointer, move to the next pointer.
Now, check if the current node's next pointer is the head pointer.
If it is, then you know you've traversed a loop and ended up back at the beginning of the list. You can therefore conclude that the list is corrupted.
If not, create another buffer pointing to the current pointer and advance the current pointer to the next one. Then set the buffer pointer's next pointer to the aforementioned buffer.
Repeat this until current -> next is NULL.
Here's a diagram (poorly) illustrating what's going on:
http://sidoh.dark-wire.net/upload/viewitem.php?id=123Here's a quick implementation of this procedure I whipped up in C last night.
http://www.christophermullins.net/index.php/codebin/viewcode/10/?window=1Here's all of the code batched together:
http://www.christophermullins.net/index.php/codebin/viewproject/3Here's what the code looks like when ran:
mullins@antero:~/src/c/ll$ make; ./ll
gcc linked_list.c -o ll
List generated: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]
Reversed list (starting at 25 -> 24 -> ...): [25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1]
Reversed list (starting at 1 -> 2 -> 3 -> ...): [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]
Attempting the reverse-pointer corruption test: 1
Corrupting list...
Attempting the reverse-pointer corruption test: 0I'll post the other solution later.