逆序输出链表

[!Tip]

本节源代码见Github链接🔗


问题描述

从表尾开始输出链表结点数据


核心思路

通过递归遍历至表尾,依次输出节点数据


实现代码

【👉🏻>>点击展开查看代码】
        
/**  
 * 逆序输出单向链表  
 *  
 * @param headNode  
 * @author: Max Solider  
 * @date: 2022/10/9 14:18  
 */
 void printListFromEnd(NormalListNode headNode) {  
    if (headNode == null) {  
        return;  
    }  
    printListFromEnd(headNode.getNext());  
    System.out.println(" " + headNode.getData() + " ");  
    return;
}
        
    

时间复杂度

时间复杂度为O(n),用于遍历链表。


空间复杂度

空间复杂度为O(n),用于栈空间。


© MaxSolider all right reserved,powered by Gitbook文件修订时间: 2022-10-12 23:29:58

results matching ""

    No results matching ""