現在、ADT実装、特にリンクリストの実装をブラッシュアップしようとしています(これを行うにはJava 5を使用しています)。リンクリストのコードレビューadd(i、x)メソッド
私は2つの質問があります。
を(1)私が正しいと効率的なアドオン(x iは、)のために書いたこの実装ですか?
public void add(int i, Object x) { // Possible Cases: // // 1. The list is non-empty, but the requested index is out of // range (it must be from 0 to size(), inclusive) // // 2. The list itself is empty, which will only work if i = 0 // // This implementation of add(i, x) relies on finding the node just before // the requested index i. // These will be used to traverse the list Node currentNode = head; int indexCounter = 0; // This will be used to mark the node before the requested index node int targetIndex = i - 1; // This is the new node to be inserted in the list Node newNode = new Node(x); if (currentNode != null) { while (indexCounter < targetIndex && currentNode.getNext() != null) { indexCounter++; currentNode = currentNode.getNext(); } if (indexCounter == targetIndex) { newNode.setNext(currentNode.getNext()); currentNode.setNext(newNode); } else if (i == 0) { newNode.setNext(head); head = newNode; } } else if (i == 0) { head = newNode; } }
(2)Iは、実施するには、この方法は非常に困難を発見しました。正直言って、それは数日かかった。私はプログラミングが大好きで、いくつかの言語やプラットフォームの中間レベルで自分自身を考えているので、これは認めがたいです。私は13歳(Apple IIcのApplesoft BASIC!)からCSを学んだのでプログラミングしてきました。私は現在、ソフトウェアテスターとして働いており、ある時点で開発者になる予定です。だから私の質問の第二の部分は、これは私が優れた仕事のタイプであると自分自身をだましているのだろうか?何かは、この方法を実装することに直面している熟練した開発者でさえ、難しいと感じています。
フィードバックとアドバイスをいただきありがとうございます。
@dvanaria:この質問はhttp://codereview.stackexchange.comに適していると思います。 –
http://codereview.stackexchange.com/ –
にありがとう、私はcodereview.stackexchangeについて聞いたことがない、それはより良い場所のように聞こえる。私は今、それを動かすことに目を向けます。 – dvanaria