예제 #1
0
        public void Remove(MyLinkedListNode <T> value)
        {
            MyLinkedListNode <T> cur = root;

            while (cur != null)
            {
                if (cur == value)
                {
                    cur.Prev.Next = cur.Next;
                    cur.Next.Prev = cur.Prev;
                    cur           = null;
                    return;
                }
                cur = cur.Next;
            }
        }
예제 #2
0
        public MyLinkedListNode <T> AddLast(T value)
        {
            MyLinkedListNode <T> newNode = new MyLinkedListNode <T>();

            if (root == null)
            {
                root      = newNode;
                root.Next = tail;
                tail      = newNode;
            }

            if (tail != null)
            {
                newNode.Prev = tail;
                tail.Next    = newNode;
                tail         = newNode;
            }
            newNode.data = value;
            return(newNode);
        }
예제 #3
0
        public void Remove(T value)
        {
            MyLinkedListNode <T> cur = root;

            while (true)
            {
                if (cur == null)
                {
                    return;
                }
                if (cur.data.Equals(value))
                {
                    break;
                }
                cur = cur.Next;
            }
            if (cur != null)
            {
                cur.Prev.Next = cur.Next;
                cur.Next.Prev = cur.Prev;
                cur           = null;
            }
        }