美文网首页
单链表反转

单链表反转

作者: 淡淡de盐 | 来源:发表于2020-08-25 11:05 被阅读0次

单链表


单链表反转

function reversal()
{
    if ($this->size == 0) {
        return $this->header;
    }

    $pre     = null;
    $current = $this->header;
    while ($current != null) {
        $tmp = $current->next;

        $current->next = $pre;

        $pre = $current;

        $current = $tmp;
    }
    $this->header = $pre;

    return $this;
}

递归方法

public function reversRecursionNode($head)
{
    if ($head->next == null) {
        return $head;
    }
    $phead            = $this->reversRecursionNode($head->next);
    $head->next->next = $head;
    $head->next       = null;

    return $phead;
}

相关文章

  • Algorithm小白入门 -- 单链表

    单链表递归反转链表k个一组反转链表回文链表 1. 递归反转链表 单链表节点的结构如下: 1.1 递归反转整个单链表...

  • 单链表反转

    单链表 单链表反转 递归方法

  • Java、Python3 实战 LeetCode 高频面试之单链

    单链表反转 单链表反转这道题可谓是链表里面的高频问题了,差不多可以说只要被问到链表,就会问单链表反转。 今天我们就...

  • 链表简单算法相关练习

    单链表反转: 给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。 迭代方式实现: 复杂度分析: 时...

  • 5个链表的常见操作

    链表 链表反转 LeetCode206:给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。 环路检...

  • 反转链表

    给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。

  • 【教3妹学算法】2道链表类题目

    题目1:反转链表 给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。 示例 1: 输入:head ...

  • js+链表

    链表结构 删除链表某节点 遍历 反转单链表

  • 反转单链表

    题目:反转单链表。

  • 单链表反转

    单链表反转 单链表初始化 输出 反转 释放 实现代码 尚未实现 元素插入 元素删除

网友评论

      本文标题:单链表反转

      本文链接:https://www.haomeiwen.com/subject/jebajktx.html