public void removeFirst() { if (first == null) { return; } first = first.next; count--; }
public IEnumerator GetEnumerator() { OneListNode node = first; while (node != null) { yield return(node.val); node = node.next; } }
public void addFirst(int x) { if (first == null) { first = new OneListNode(x); return; } OneListNode node = new OneListNode(x); node.next = first; first = node; count++; }
public int getIndex(int index) { if (index >= count) { return(0); } OneListNode node = first; while (index > 0) { node = node.next; index--; } return(node.val); }
public int getLast() { if (first == null) { return(0); } OneListNode temp = first; OneListNode father = temp; while (temp != null) { father = temp; temp = temp.next; } return(father.val); }
public void removeLast() { if (first == null) { return; } OneListNode temp = first; OneListNode father = temp; while (temp != null) { father = temp; temp = temp.next; } father = null; count--; }
public void addLast(int x) { if (first == null) { first = new OneListNode(x); return; } OneListNode temp = first; OneListNode father = temp; while (temp != null) { father = temp; temp = temp.next; } father.next = new OneListNode(x); count++; }
public void addIndex(int index, int x) { if (index >= count) { return; } OneListNode temp = first; while (index > 0) { temp = temp.next; index--; } OneListNode node = new OneListNode(x); node.next = temp.next; temp.next = node; count++; }
public OneListNode invert() { if (first == null) { return(null); } OneListNode node = first; OneListNode pre = null; OneListNode next = null; while (node != null) { next = node.next; node.next = pre; pre = node; node = next; } return(pre); }