以下是根据您提供的要求用Java编写的代码:
”`java
public class DoublyList
private Node<T> head;
private Node<T> tail;
public DoublyList() {
head = null;
tail = null;
}
public boolean isEmpty() {
return (head == null);
}
public String toString() {
StringBuilder sb = new StringBuilder();
Node<T> current = head;
while (current != null) {
sb.append(current.data).append(" ");
current = current.next;
}
return sb.toString().trim();
}
public DoublyList(T[] values) {
for (T value : values) {
addLast(value);
}
}
public DoublyList(DoublyList<T> list) {
Node<T> current = list.head;
while (current != null) {
addLast(current.data);
current = current.next;
}
}
public void concat(int i, DoublyList<T> list) throws IndexOutOfBoundsException {
if (i < 0 || i > size()) {
throw new IndexOutOfBoundsException();
}
if (list.isEmpty()) return;
if (i == 0) { // Concat at the beginning
list.tail.next = head;
head.prev = list.tail;
head = list.head;
} else if (i == size()) { // Concat at the end
tail.next = list.head;
list.head.prev = tail;
tail = list.tail;
<br/><br/><br/><font size=1 color=#CCCCCC>内容由零声教学AI助手提供,问题来源于学员提问</font>




