首页 > 编程语言 >数据结构 玩转数据结构 5-6 递归算法的调试

数据结构 玩转数据结构 5-6 递归算法的调试

时间:2022-11-01 22:35:35浏览次数:67  
标签:Null 递归 int null 玩转 数据结构 调试

0    课程地址

https://coding.imooc.com/lesson/207.html#mid=13442

 

1    重点关注

1.1    递归算法的调试打印日志层级调试

参考3.1

 

2    课程内容


3    Coding

3.1    递归算法的调试打印日志层级调试

  • 调试类:
package com.company;

/**
 *  使用递归实现
 *  203问题解决 删除链表的元素
 * @author weidoudou
 * @date 2022/11/1 10:47
 **/
class Solution3 {
    public ListNode removeElements(ListNode head, int val,int depth) {
        //1 基本方法
        if(null==head){
            return null;
        }

        for(int i = 0;i<depth;i++){
            System.out.print("==");
        }
        System.out.println(head);

        depth = depth+1;


        //2 方法拆分
        ListNode cur = removeElements(head.next,val,depth);

        if(head.val==val){
            for(int i = 0;i<depth;i++){
                System.out.print("==");
            }
            System.out.println(cur);

            return cur;
        }else{
            head.next = cur;
            for(int i = 0;i<depth;i++){
                System.out.print("==");
            }
            System.out.println(head);
            return head;
        }

    }

    public static void main(String[] args) {
        int[] nums = {1,2,6,3,4,5,6};
        ListNode listNode = new ListNode(nums);
        //System.out.println(listNode);


        ListNode res =  new Solution3().removeElements(listNode,6,0);
        System.out.println(res);
    }
}

 

  • 测试结果:
1->2->6->3->4->5->6->Null
==2->6->3->4->5->6->Null
====6->3->4->5->6->Null
======3->4->5->6->Null
========4->5->6->Null
==========5->6->Null
============6->Null
==============null
============5->Null
==========4->5->Null
========3->4->5->Null
======3->4->5->Null
====2->3->4->5->Null
==1->2->3->4->5->Null
1->2->3->4->5->Null

Process finished with exit code 0

 

标签:Null,递归,int,null,玩转,数据结构,调试
From: https://www.cnblogs.com/1446358788-qq/p/16849393.html

相关文章