程序员面试宝典之数据结构基础----单链表的逆序打印

来源:互联网 发布:以下哪件商品能在淘宝上发布 编辑:程序博客网 时间:2024/05/17 04:32

单链表的逆序有两种方法,递归和非递归,前面已经有具体的实现,这里把单链表的逆序输出单独拿出来,因为这里用的递归方法比较巧妙,当然,可以先把单链表逆序,然后再顺序打印出,也是可以的,这里直接用递归的方法实现打印:

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.    }}