public void add(int index, Node nde) { if (nde == null) return; if (index == 0) { // This makes it the first element in the list. nde.insertBefore(head); head = nde; } else if (index == size) { // Because the list is circular this // makes it the last element in the list. nde.insertBefore(head); } else { Node after = head; while (index != 0) { after = after.getNext(); index--; } nde.insertBefore(after); } size++; }
public void add(int index, Node nde) { if (nde == null) return; if (index == 0) { // This makes it the first element in the list. nde.insertBefore(head); head = nde; } else if (index == size) { // Because the list is circular this // makes it the last element in the list. nde.insertBefore(head); } else { Node after = head; while (index != 0) { after = after.getNext(); index--; } nde.insertBefore(after); } size++; }
/** * Removes nde from the list it is part of (should be this * one, otherwise results are undefined). If nde is the * current head element, then the next element becomes head, * if there are no more elements the list becomes empty. * @param nde node to remove. */ public void remove(Node nde) { if (nde == null) return; if (nde == head) { if (head.getNext() == head) head = null; // Last node... else head = head.getNext(); } nde.unlink(); size--; }
public void add(int index, Node nde) { if (nde == null) return; if (index == 0) { // This makes it the first element in the list. nde.insertBefore(head); head = nde; } else if (index == size) { // Because the list is circular this // makes it the last element in the list. nde.insertBefore(head); } else { Node after = head; while (index != 0) { after = after.getNext(); index--; } nde.insertBefore(after); } size++; }
/** * Removes nde from the list it is part of (should be this * one, otherwise results are undefined). If nde is the * current head element, then the next element becomes head, * if there are no more elements the list becomes empty. * @param nde node to remove. */ public void remove(Node nde) { if (nde == null) return; if (nde == head) { if (head.getNext() == head) head = null; // Last node... else head = head.getNext(); } nde.unlink(); size--; }
/** * Removes nde from the list it is part of (should be this * one, otherwise results are undefined). If nde is the * current head element, then the next element becomes head, * if there are no more elements the list becomes empty. * @param nde node to remove. */ public void remove(Node nde) { if (nde == null) return; if (nde == head) { if (head.getNext() == head) head = null; // Last node... else head = head.getNext(); } nde.unlink(); size--; }