単独でリンクされたリスト - 取得および追加方法

Dobrikella:

私は実装を完了することによってSLListクラスを実装しようとしているので:

get(i)set(i, x)add(i, x)、およびremove(i)操作、各々がO(1 + I)時間で実行されています。

私は私のプログラムに苦しんだことはADDとgetメソッドです。私はエラーを得続けるincompatible types: SLList<T>.Node cannot be converted to intともincompatible types: SLList<T>.Node cannot be converted to int

私は非常にそれらを修正する方法へと混同しています。私はちょうど今日リンクリストについて学んだと私はそれらの概念を把握するのに苦労しています。すべてのヘルプやヒントは本当にいただければ幸いです。

public T get(int i) {
    // TODO: Implement this
    Node u = head;
    for(int j = 0; j < i; j++){
        i = u.next;
    }
    return u;
    if (i < 0 || i > n - 1) throw new IndexOutOfBoundsException();
    return null;
}


public void add(int i, T x) {
        Node u = new Node();
        u.x = x;
        if (i == 0) {
            head = u;
        } else {
            tail.next = u;
        }
        tail = u;
        i++;
        return true;
        if (i < 0 || i > n) throw new IndexOutOfBoundsException();
}

彼らがそうであるように私は、各機能Tボイド必見の滞在の種類を言及する必要があります。また、私は、私は私のコードではIndexOutOfBoundsException部分を含めるべきであると考えています。

君たちはそのここに私の完全なコードを表示する場合:https://pastebin.com/nJ9iMjxj

Mohsen_Fatemi:

あなたにはnode、クラスのタイプがnextありnode、あなたの中にいる間、get方法、あなたが代入されているnode整数の変数に:

i = u.next;

私はあなたの全体の実装が表示されていないが、私はそれがあるべきだと思います u = u.next;

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=312984&siteId=1