public T PopFirst() { if (head == null) { return(default(T)); } if (tail == head) { tail = null; } T ret = head.val; ChainNode <T> k = head.next; head.next = null; if (k != null) { k.pre = null; } //DestoryNode(head); ChainNode <T> .Destroy(head); head = k; count--; return(ret); }
public T PopBack() { if (tail == null) { return(default(T)); } T ret = tail.val; ChainNode <T> k = tail.pre; if (k != null) { k.next = null; ChainNode <T> .Destroy(tail); tail = k; } else { ChainNode <T> .Destroy(tail); head = tail = null; } count--; return(ret); }
/// <summary> /// 警告:别的链表的东西别拿过来哈,出问题了不管 /// </summary> /// <param name="chainNode"></param> public void RemoveX(ChainNode <T> chainNode) { if (head == null || chainNode == null) { return; } if (chainNode == tail) { tail = chainNode.pre; } if (chainNode.pre == null) { head = chainNode.next; if (head != null) { head.pre = null; } count--; } else { chainNode.pre.next = chainNode.next; if (chainNode.next != null) { chainNode.next.pre = chainNode.pre; } count--; } chainNode.next = null; chainNode.pre = null; chainNode.val = default(T); //DestoryNode(chainNode); ChainNode <T> .Destroy(chainNode); }