reverse a string or linked list