Пример #1
0
 public boolean add(int pos, T value) {
   LNode newNode = new LNode(value);
   LNode temp = start;
   LNode after;
   int index = 0;
   if (pos >= 0 && pos <= getSize()) {
     if (getSize() == 0 || pos == getSize()) {
       add(value);
     } else {
       while (index < pos - 1) {
         temp = temp.getNext();
         index++;
       }
       if (pos == 0) {
         after = temp;
         start = newNode;
         // new
         after.setPrevious(start);
         start.setNext(after);
         //		    start.getNext().setPrevious();
       } else {
         after = temp.getNext();
         // new
         after.setPrevious(newNode);
         newNode.setPrevious(temp);
         temp.setNext(newNode);
         newNode.setNext(after);
       }
       size++;
     }
     return true;
   } else {
     throw new IndexOutOfBoundsException();
   }
 }
Пример #2
0
 public boolean add(T value) {
   if (getSize() == 0) {
     start = new LNode(value);
     end = start;
     size++;
   } else {
     // new
     LNode newNode = new LNode(value);
     newNode.setPrevious(end);
     end.setNext(newNode);
     //	    end.getNext().setPrevious(end);
     end = end.getNext();
     size++;
   }
   return true;
 }