Note: In reverse function, we cannot use p is not end.next to decide whether to break because during reverse, the node that end points to will be inserted after head.
Since node of pointer end is changing its position, thus it won’t help us terminate the loop.