answersLogoWhite

0

Don't know how you'd do it recursively, but an iterative version might look something like:

struct Node {

int data;

Node* next;

};

struct List {

Node* head;

};

void reverse(List& list) {

Node* head = list.head;
Node* next;


if (head == 0) return;


while (next = head->next) {
head->next = next->next;
next->next = list.head;
list.head = next;

}


}


This is untested, but the gist is simple: for each element in the list, move it to the front of the list.

User Avatar

Wiki User

16y ago

What else can I help you with?

Related Questions

Free download depth first search source code in java and c plus plus?

// Let's assume we're traversing an n-ary tree. // This interface is what each node in the tree implements. public interface Node { int getValue(); List<Node> getChildren(); } // Search the tree in depth public static List<Node> depthFirstTraversal(Node root) { // Create a list of nodes to process, starting with the root node. final List<Node> nodes = new LinkedList<Node>(); nodes.add(root); // Recursively add all children of all nodes of root to nodes for (Node n : root.getChildren()) { nodes.addAll(depthFirstTraversal(n)); } return nodes; }


What is b plus b plus b plus c plus c plus c plus c?

b+b+b+c+c+c+c =3b+4c


What is c plus c plus 2c plus c plus c equal?

c + c + 2c + c + c = 6c


B plus b plus b plus c plus c plus c plus c equals?

b + b + b + c + c + c + c = 3b + 4c


Symplify c plus c plus c plus c?

4c


What is c plus c plus c plus c plus c?

c + c + c + c + c = 5 * c.


Primary and secondary key in c and c plus plus?

There are no "primary and secondary keys" in c and c plus plus.


What is c plus C plus C answer in algebra?

3c


What is the different between turbo c plus plus and unix c plus plus?

There is no such thing as 'unix C++'.


What to Do if Macros does not exist in C and C plus plus?

They do exist in C and C++.


If A equals 4.0GPA than C plus equals?

C plus is between 3 and 3.2. C = 75% 0% < Plus < 5% 75%+0% < C Plus < 75%+5% 75 < C Plus < 80% 75%*4 < C Plus < 80% * 4 (3/4)*4 < C Plus < (4/5) * 4 3 < C Plus < 16/5 3 < C Plus < 3.2


Can you rewrite a cuda file in c c plus plus language?

Yes, you can rewrite a cuda program originally written in c in c plus plus.