DoublyLinkedListプロジェクト:入力の例
-
27-10-2019 - |
質問
私は現在、大学のJavaコースで二重にリンクされたリストプロジェクトに取り組んでいます。二重にリンクされたリスト、リンクされたリスト、リストの概念を理解しています。しかし、自分のメソッドで変更する必要があるデータを作成する方法がわからないため、プログラムを作成するのに多くの問題が発生しています。私たちの教授は通常、彼が使用する情報を私たちに与えますが、今回はしませんでした、そして私は私の研究でそれを理解することができないようです。
私の主な質問は、誰かが私のために私のために仕事を始めて、私の方法をより良くするために必要なことを理解し始めるためにいくつかのコードを書くことができると思いますか?
これが私がこれまでに持っているものです。 (基本的にはオーバーライドスケルトンだけです。)
助けてくれてありがとう。
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
public class DoublyLinkedList<E> implements List<E>{
DoublyLinkedListNode header;
public static void main(String[] args) {
}
public boolean add(E e) {
return false;
}
public void add(int index, E element) {
}
public boolean addAll(Collection<? extends E> c) {
return false;
}
public void clear() {
header=null;
}
public boolean contains(Object o) {
return false;
}
public E get(int index) {
return null;
}
public int indexOf(Object o) {
return 0;
}
public boolean isEmpty() {
return header == null;
}
public int lastIndexOf(Object o) {
return 0;
}
public ListIterator<E> listIterator() {
return null;
}
public boolean remove(Object o) {
return false;
}
public E remove(int index) {
return null;
}
public int size() {
return 0;
}
public Object[] toArray() {
return null;
}
private class DoublyLinkedListNode{
DoublyLinkedListNode next;
DoublyLinkedListNode last;
E contents;
}
//extra credit
private class DoublyLinkedListItr implements java.util.ListIterator{
public void add(Object arg0) {
}
public boolean hasNext() {
return false;
}
public boolean hasPrevious() {
return false;
}
public Object next() {
return null;
}
public int nextIndex() {
return 0;
}
public Object previous() {
return null;
}
public int previousIndex() {
return 0;
}
public void remove() {
}
public void set(Object arg0) {
}
}
public ListIterator<E> listIterator(int index) {
throw new UnsupportedOperationException("not implemented");
}
public <T> T[] toArray(T[] a) {
throw new UnsupportedOperationException("not implemented");
}
public List<E> subList(int fromIndex, int toIndex) {
throw new UnsupportedOperationException("not implemented");
}
public boolean retainAll(Collection<?> c) {
throw new UnsupportedOperationException("not implemented");
}
public E set(int index, E element) {
throw new UnsupportedOperationException("not implemented");
}
public boolean removeAll(Collection<?> c) {
throw new UnsupportedOperationException("not implemented");
}
public boolean addAll(int index, Collection<? extends E> c) {
throw new UnsupportedOperationException("not implemented");
}
public Iterator<E> iterator() {
throw new UnsupportedOperationException("not implemented");
}
public boolean containsAll(Collection<?> c) {
throw new UnsupportedOperationException("not implemented");
}
}
解決
ここでデータを作成するためのスニペットは次のとおりです。
public static void main(String[] args) {
DoublyLinkedList<String> doublyLinkedList = new DoublyLinkedList<String>();
doublyLinkedList.add("Hello");
doublyLinkedList.add("World");
// If you want to store int
DoublyLinkedList<Integer> dlli = new DoublyLinkedList<Integer>();
dlli.add(new Integer(10));
dlli.add(new Integer(5));
}
これがあなたが探しているものであることを願っています。
他のヒント
ノードを作成し、値を保存します。
ヘッダーがnullの場合、ヘッダーに新しいノードを参照してください。
ヘッダーがnullでない場合は、指摘されたノードを取り、次にnullでない限り、次のノードを参照してください。次にnullの場合は、リストの最後にある場合は、次の参照を取り、新しく作成したノードを参照してもらいます。次に、新しいノードの最後の(以前に電話したことがあります)リファレンスを取り、見つけたノード(リストの終わり)を参照してもらいます。
それはあなたを始めさせるはずです。
所属していません StackOverflow