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); }
public static void Destroy(ChainNode <T> cn) { cn.val = default(T); cn.next = null; cn.pre = null; cn.next = cache; cache = cn; }
public bool MoveNext() { if (iterator != null) { iterator = iterator.next; } return(iterator != null); }
public void DoChain(Action <T> action) { ChainNode <T> k = head; while (k != null) { action(k.val); k = k.next; } }
public void RemoveCurrent() { if (iterator == null) { return; } ChainNode <T> k = iterator; MoveNext(); RemoveX(k); }
public static ChainNode <T> Create() { if (cache == null) { return(new ChainNode <T>()); } else { var x = cache; cache = cache.next; x.pre = x.next = null; return(x); } }
public void RemoveX(Predicate <T> _Pre) { ChainNode <T> k = head; while (k != null) { ChainNode <T> next = k.next; if (_Pre(k.val)) { RemoveX(k); } k = next; } }
public void Clear() { ChainNode <T> k = head; while (k != null) { ChainNode <T> next = k.next; k.next = null; k.pre = null; k = next; } head = null; tail = null; count = 0; }
public ReturnType FirstMatch <ReturnType>(Predicate <T> predFn, Converter <T, ReturnType> convertFunc) { ChainNode <T> k = head; while (k != null) { iterator = k; if (predFn(Current)) { return(convertFunc(Current)); } k = k.next; } return(default(ReturnType)); }
public bool Contains(T v) { ChainNode <T> k = head; while (k != null) { if (k.val.Equals(v)) { iterator = k; return(true); } k = k.next; } return(false); }
public void Add(T val) { ChainNode <T> k = ChainNode <T> .Create(); k.val = val; k.next = null; if (tail != null) { k.pre = tail; tail.next = k; tail = k; } else { head = k; tail = k; k.pre = null; } count++; }
public void AddAtFirst(T val) { ChainNode <T> k = ChainNode <T> .Create(); k.val = val; k.pre = null; if (head != null) { k.next = head; head.pre = k; head = k; } else { head = k; tail = k; k.next = null; } count++; }
public bool MoveHead() { iterator = head; return(iterator != null); }