单链表逆序,非递归
typedef struct list
{
int date;
struct list *next;
}node;
node * reverse_list(node *head)
{
if(head == NULL || head->next == NULL)
return head;
else
{
node *reverse_head = NULL;
node *currrent = head;
if(current)
{
node *temp = current;
current = current->next;
temp ->next = reverse_head;
reverse_head = temp;
}
return reverse_head;
}
}
递归方式代码
node *reverse_list(head)
{
if(head == NULL || head->next == NULL)
{
return head;
}
else
{
node *current = head->next;
node *reversr_head = reverse_list(current);
current->next = head;
head->next = NULL;
return reverrse_head;
}
}