예제 #1
0
        public bool Contains(MyLinkedListNode <T> item)
        {
            if (_head == null)
            {
                return(false);
            }

            long index = 0;

            do
            {
                if (GetNodeAt(index++) == item)
                {
                    return(true);
                }
            } while (index < _count);

            return(false);
        }
예제 #2
0
        public void Remove(MyLinkedListNode <T> item)
        {
            if (_head == null)
            {
                return;
            }

            var node  = _head;
            var index = 0;

            do
            {
                if (node == item)
                {
                    RemoveAt(index);
                    break;
                }
                node = node.Next;
                index++;
            } while (node != null);
        }
예제 #3
0
        private long GetIndexFrom(MyLinkedListNode <T> node)
        {
            if (node == null)
            {
                throw new ArgumentNullException();
            }
            var  current = _head;
            long index   = 0;

            for (int i = 0; i < _count; i++)
            {
                if (node == current)
                {
                    return(index);
                }
                else
                {
                    current = current.Next;
                    index++;
                }
            }
            throw new ArgumentOutOfRangeException();
        }
예제 #4
0
        public void AddAfter(MyLinkedListNode <T> itemToAdd, MyLinkedListNode <T> relItem)
        {
            var index = GetIndexFrom(relItem);

            InsertAt(index + 1, itemToAdd);
        }
예제 #5
0
 public void Add(MyLinkedListNode <T> item)
 {
     InsertAt(_count, item);
 }