Reversing a linked list
If you don't care about the origin list, we can use the head of it as the iterator, You should return the new head after reverse, or the new list will lost.


#include &lt;stdio.h&gt;

struct Node
{
    int data;
    Node* next;
    Node(int value, Node* ptr):data(value), next(ptr){} 
};

// Reverse list and return the new head
Node* reverse_list(Node* head)
{
    Node* p = NULL;
    Node* q = head;
    while(q)
    {
        Node* t = q-&gt;next;
        q-&gt;next = p;
        p = q;
        q = t;
    }

    return p; // new head
}

void print_list(Node* head)
{
    Node* t = head;
    while(t)
    {
        printf("%d\n", t-&gt;data);
        t = t-&gt;next;
    }
}

void main()
{
    Node* head = new Node(1, NULL);
    Node* p = head;
    for(int i = 2; i &lt; 10; ++i)
    {
        p-&gt;next = new Node(i, NULL);
        p = p-&gt;next;
    }
    print_list(head);

    Node* newHead = reverse_list(head);
    print_list(newHead);

    getchar();
}