Linked list reversal and loop detection