单链表的逆序有两种方法,递归和非递归,前面已经有具体的实现,这里把单链表的逆序输出单独拿出来,因为这里用的递归方法比较巧妙,当然,可以先把单链表逆序,然后再顺序打印出,也是可以的,这里直接用递归的方法实现打印:
void print_reverse_list(node* head)
{
assert(head);
else if(head->next == NULL)
printf("%d\n",head->data);//print the last node
else
{
print_reverse_list(head->next);
printf("%d\n",head->data);//print other nodes.
}
}