Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 删除LinkedList中出现的子列表_Java_Linked List_Doubly Linked List - Fatal编程技术网

Java 删除LinkedList中出现的子列表

Java 删除LinkedList中出现的子列表,java,linked-list,doubly-linked-list,Java,Linked List,Doubly Linked List,我正在尝试解决一个问题,该问题应该删除给定列表中出现的子列表。 例如:输入: 列表:a b c d b c a e a e 子列表:bc 输出:a d a e a e 谁能给我一些建议或提示我怎么做。我的代码出现空指针异常。 public static void deleteSublist(DLL<Character> lista1, DLL<Character> lista2){ DLL<Character> finalList = new DLL&

我正在尝试解决一个问题,该问题应该删除给定列表中出现的子列表。
例如:
输入:
列表:a b c d b c a e a e
子列表:bc
输出:a 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;
    }


}
publicstaticvoiddeletesublist(DLL列表a1、DLL列表a2){
DLL finalList=新DLL();
DLLNode node1=lista1.getFirst();
DLLNode temp=lista1.getFirst();
DLLNode node2=lista2.getFirst();
int len1=lista1.length();
int len2=lista2.length();
整数计数=0;
布尔检查=假;
while(node1!=null){
检查=错误;
node2=lista2.getFirst();
温度=节点1;
while(temp!=null){
如果(!temp.element.equals(node2.element)){
check=true;//无子列表
打破
}
温度=成功温度;
node2=node2.succ;
}
如果(!check){//我们有子列表
//在这里我应该删除子列表
}
node1=node1.succ;
}
}

NPE在哪里抛出?@Mick助记符它在temp=temp.行中抛出。。。这似乎不太可能,因为这意味着
temp
将是
null
,这意味着
temp!=null
将产生
false
temp.element
将导致NPE。顺便说一句:这将是查找子列表的有效方法。@fabian i删除了while(temp!=null)中除temp=temp.succ之外的所有内容,并且它仍然会产生NPE。真烦人