コード例 #1
0
            public bool MoveNext()
            {
                if (node == null)
                {
                    index = list.Count + 1;
                    return(false);
                }

                ++index;
                Current = node.Value;
                node    = node.next;
                if (node == list.head)
                {
                    node = null;
                }
                return(true);
            }
コード例 #2
0
 internal void InternalRemoveNode(MyLinkedListNode <T> node)
 {
     if (node.next == node)
     {
         head = null;
     }
     else
     {
         node.next.prev = node.prev;
         node.prev.next = node.next;
         if (head == node)
         {
             head = node.next;
         }
     }
     node.Invalidate();
     Count--;
 }
コード例 #3
0
        public MyLinkedListNode <T> FindLast(T value)
        {
            if (head == null)
            {
                return(null);
            }

            MyLinkedListNode <T> last = head.prev;
            MyLinkedListNode <T> node = last;
            EqualityComparer <T> c    = EqualityComparer <T> .Default;

            if (node != null)
            {
                if (value != null)
                {
                    do
                    {
                        if (c.Equals(node.Value, value))
                        {
                            return(node);
                        }

                        node = node.prev;
                    } while (node != last);
                }
                else
                {
                    do
                    {
                        if (node.Value == null)
                        {
                            return(node);
                        }
                        node = node.prev;
                    } while (node != last);
                }
            }
            return(null);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: TatevikBarseghyan/courses
        static void Main(string[] args)
        {
            MyLinkedList <int> list = new MyLinkedList <int>();

            list.AddLast(10);
            list.AddLast(20);
            var node = list.AddLast(30);

            //MyLinkedListNode<int> node = new MyLinkedListNode<int>(list, -1000);
            list.AddAfter(node, -1000);

            foreach (int value in list)
            {
                Console.WriteLine(value);
            }

            MyLinkedListNode <int> node30 = list.Find(30);
            MyLinkedListNode <int> node20 = list.FindLast(20);

            if (list.Contains(30))
            {
            }

            int[] arr = new int[list.Count];
            list.CopyTo(arr, 0);

            Array array = new object[list.Count];

            list.CopyTo(array, 0);

            list.RemoveFirst();
            list.RemoveLast();

            list.Clear();

            Console.ReadLine();
        }
コード例 #5
0
 public void AddAfter(MyLinkedListNode <T> node, MyLinkedListNode <T> newNode)
 {
     InternalInsertNodeBefore(node.next, newNode);
     newNode.List = this;
 }
コード例 #6
0
 void IEnumerator.Reset()
 {
     Current = default;
     node    = list.head;
     index   = 0;
 }
コード例 #7
0
        public void CopyTo(Array array, int index)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }

            if (array.Rank != 1)
            {
                throw new ArgumentException("MultiRank");
            }

            if (array.GetLowerBound(0) != 0)
            {
                throw new ArgumentException("Non Zero Lower Bound");
            }

            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index");
            }

            if (array.Length - index < Count)
            {
                throw new ArgumentException("");
            }

            T[] tArray = array as T[];
            if (tArray != null)
            {
                CopyTo(tArray, index);
            }
            else
            {
                //
                // Catch the obvious case assignment will fail.
                // We can found all possible problems by doing the check though.
                // For example, if the element type of the Array is derived from T,
                // we can't figure out if we can successfully copy the element beforehand.
                //
                Type targetType = array.GetType().GetElementType();
                Type sourceType = typeof(T);
                if (!(targetType.IsAssignableFrom(sourceType) || sourceType.IsAssignableFrom(targetType)))
                {
                    throw new ArgumentException("Invalid Array Type");
                }

                object[] objects = array as object[];
                if (objects == null)
                {
                    throw new ArgumentException("Invalid Array Type");
                }
                MyLinkedListNode <T> node = head;
                try
                {
                    if (node != null)
                    {
                        do
                        {
                            objects[index++] = node.Value;
                            node             = node.next;
                        } while (node != head);
                    }
                }
                catch (ArrayTypeMismatchException)
                {
                    throw new ArgumentException("Invalid Array Type");
                }
            }
        }
コード例 #8
0
 public void Remove(MyLinkedListNode <T> node)
 {
     InternalRemoveNode(node);
 }