单向链表倒序操作

struct node
{
    int data;
    node* next;
};

// 单向链表头,如何倒序操作
inverse(node* head)
{
node thead;
thead.next = NULL;
for(current = head; current!=null; )
{
     if ( current == head )
     {
node * t = current->next;
         thead.next = current;
current->next = NULL;
         current = t;   
     }
     else
     {
     node * t = current->next;
        node* t2 = thead.next;

        thead.next = current;
        current->next = t2;        

        current = t;    
     }
}

return thead.next;

}

你可能感兴趣的:(面试)