每日一刷——删除无头链表非尾结点&倒序打印链表

来源:互联网 发布:手机淘宝哪儿有一元抢 编辑:程序博客网 时间:2024/06/15 18:59

倒序打印链表
采用递归的方法

void PrintReverse(Node* head){    assert(head);    if (head->_next)    {        PrintReverse(head->_next);    }    printf("%d->",head->_data);}

删除无头链表非尾结点

void Del_N_tail(SListNode* pos) //删除一个无头链表的非尾结点  {   //删除pos的下一个结点,删除之前把值传给pos结点   if (pos->next)   {    pos->data = pos->next->data;    SListNode *tmp = pos->next;    pos->next = tmp->next;    free(tmp);    tmp = NULL;   }  }  
原创粉丝点击