使用Java,我有一个链接的LList类和一个LLNode类。我试图从我的链接列表中删除一个元素,通过返回一个没有元素的新链接列表。基本上,如果列表不包含特定的元素,那么返回它,但如果它确实创建一个新的。我遍历我的当前列表,看看它是否包含元素e,不完全确定如何创建没有特定元素的列表。链接列表,通过返回新列表删除元素
public LList<T> remove(T t) {
if (this.contains(t)) {
LList<T> newList = new LLSet<>(this.head);
newList.head = new LLNode<>(, this.head);
return newList;
}
return this;
}