/// <summary> /// 刪除指定的節點 /// </summary> /// <param name="node"></param> public void Delete(MyListNode node) { if (node == null) { return; } var prevNode = node.Previous; var nextNode = node.Next; prevNode.Next = nextNode; nextNode.Previous = prevNode; Count--; }
/// <summary> /// 將數字加到指定節點之後 /// </summary> /// <param name="node">指定節點</param> /// <param name="value">數字</param> /// <returns></returns> public MyListNode InsertAfter(MyListNode node, int value) { var insertNode = new MyListNode { Value = value }; var pervNode = node; var nextNode = node.Next; insertNode.Previous = pervNode; insertNode.Next = nextNode; pervNode.Next = insertNode; nextNode.Previous = insertNode; Count++; return(insertNode); }
/// <summary> /// 建構子 /// </summary> public MyList() { m_Root = new MyListNode(); m_Root.Next = m_Root; m_Root.Previous = m_Root; }
/// <summary> /// 將數字加到指定節點之前 /// </summary> /// <param name="node">指定節點</param> /// <param name="value">數字</param> /// <returns></returns> public MyListNode InsertBefore(MyListNode node, int value) { return(InsertAfter(node.Previous, value)); }