删除LinkedList中子列表的出现

时间:2015-06-07 23:16:32

标签: java linked-list doubly-linked-list

我正在尝试解决一个应该删除给定列表中子列表出现的问题 例如:
输入:
清单:a b c d d b c e e a 子列表:b c
输出:a d d a e a e
任何人都可以给我一些建议或一些提示我该怎么做。我的代码给出了空指针异常。

public static void deleteSublist(DLL<Character> lista1, DLL<Character> lista2){
    DLL<Character> finalList = new DLL<Character>();
    DLLNode<Character> node1 = lista1.getFirst();
    DLLNode<Character> temp = lista1.getFirst();
    DLLNode<Character> node2 = lista2.getFirst();
    int len1 = lista1.length();
    int len2 = lista2.length();
    int count = 0;
    boolean check = false;

    while(node1 != null){
        check = false;
        node2 = lista2.getFirst();
        temp = node1;

        while(temp != null){
            if(!temp.element.equals(node2.element)){
                check = true; // no sublist
                break;
            }
            temp = temp.succ;
            node2 = node2.succ;
        }

        if(!check){             //we have sublist
                //Here I should delete sublist
        }

        node1 = node1.succ;
    }


}

0 个答案:

没有答案