代码测试

public class Test {
    Node headnode1 = new Node();
    Node headnode2 = new Node();

    // static Node headnode2=new Node();
    @Before
    public void beforeTest1() {
        headnode1.data = 5;
        Node node2 = new Node();
        node2.data = 6;
        Node node3 = new Node();
        node3.data = 12;
        Node node4 = new Node();
        node4.data = 14;
        headnode1.next = node2;
        node2.next = node3;
        node3.next = node4;
        //  node4.next=node2; //有环无环

        Node headnode1Copy = new Node(headnode1);
        while (headnode1Copy != null) {
            System.out.print(headnode1Copy.data + "--");
            headnode1Copy = headnode1Copy.next;
        }
        System.out.println();

    }

    @Before
    public void beforeTest2() {
        headnode2.data = 7;
        Node node2 = new Node();
        node2.data = 8;
        Node node3 = new Node();
        node3.data = 13;
        headnode2.next = node2;
        node2.next = node3;
    }


    @org.junit.Test
    public void testReverse() {
        ListReverse listReverse = new ListReverse();
        System.out.println("----------" + headnode1.data);
        Node node = listReverse.reverse(headnode1);
        System.out.println("----------" + node.data);
    }

    @org.junit.Test
    public void testCheckCircle() {
        CheckCircle checkCircle = new CheckCircle();
        HashMap map = checkCircle.isCircle(headnode1);
        boolean flag = map.containsKey(true);
        int len = checkCircle.length(headnode1);
        System.out.println(flag + "-----" + len);
    }

    @org.junit.Test
    public void testInsert() {

        InsertList insertList = new InsertList();
        // Node node=insertList.Insert(headnode2,headnode1);
        Node node = insertList.Merge(headnode1, headnode2);

        while (headnode1 != null) {
            System.out.print(headnode1.data + "--");
            headnode1 = headnode1.next;
        }
        System.out.println();
        while (headnode2 != null) {
            System.out.print(headnode2.data + "--");
            headnode2 = headnode2.next;
        }
        System.out.println();
        while (node != null) {
            System.out.print(node.data + "--");
            node = node.next;
        }
    }

    @org.junit.Test
    public void testDeleteBackN() {
        DeleteBackN deleteBackN = new DeleteBackN();
        deleteBackN.deleteBackN(headnode1, 3);
        while (headnode1 != null) {
            System.out.print(headnode1.data + "--");
            headnode1 = headnode1.next;
        }
    }

    @org.junit.Test
    public void testMiddle() {
        MiddleNode middleNode = new MiddleNode();
        Node resultNode = middleNode.middle(headnode1);

            System.out.print(resultNode.data + "--");

    }
}
View Code
public class Node {

    public int data;
    public Node next = null;

    public Node(Node node) {
        this.data = node.data;
        this.next = node.next;
    }

    public Node(int data) {
        this.data = data;
        this.next = null;

    }

    public Node() {
        this.data = 0;
        this.next = null;
    }

}
View Code

 

转载于:https://www.cnblogs.com/zecdllg/p/9767075.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值