ZBLOG

void addAll(int i, DoublyList list)用java写,其中包括class DoublyList,DoublyList(),boolean isEmpty(),String toString(),DoublyList(T[] values),DoublyList(DoublyList list),void concat(int i, DoublyList list),void addAll(int i, DoubleList lis...

以下是根据您提供的要求用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>

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=8563

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?