Write a C function that reverses a single-linked list
Anónimo
JAVA: public static Node reverse(Node node){ // if the list is a single node -> nothing to reverse if(node.next == null) return node; // else there are 2 or more nodes Node newHead = node.next; // mark the end of the list node.next = null; Node newHeadNext; while(true){ // if there is continuity after newHead if(newHead.next != null){ newHeadNext = newHead.next; // the reverse move newHead.next = node; // move the nodes to their new place node = newHead; newHead = newHeadNext; } else{ // the reverse move newHead.next = node; return newHead; } } }