单链表逆序

来源:互联网 发布:maven 指定java home 编辑:程序博客网 时间:2024/06/06 17:14
单链表逆序,非递归

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



0 0
原创粉丝点击