Beispiel #1
0
        public void Insert(int index, T item)
        {
            if (item == null)
            {
                throw new ArgumentNullException();
            }
            if (index < StartIndex || index >= Count + StartIndex)
            {
                throw new IndexOutOfRangeException();
            }
            int i = StartIndex;

            if (index == StartIndex)
            {
                IndexArrayElement <T> Element = new IndexArrayElement <T>(head.Value);
                Element.Next = head.Next;
                head.Value   = item;
                Count++;
            }
            IndexArrayElement <T> temp = head;

            while (i != index)
            {
                temp = temp.Next;
                i++;
            }

            IndexArrayElement <T> newElement = new IndexArrayElement <T>(item);

            newElement.Next = temp.Next;
            temp.Next       = newElement;
            Count++;
        }
Beispiel #2
0
        public T this[int index]
        {
            get
            {
                if (index < StartIndex || index >= Count + StartIndex)
                {
                    throw new IndexOutOfRangeException();
                }
                int i = StartIndex;
                IndexArrayElement <T> temp = head;
                while (i != index)
                {
                    temp = temp.Next;
                    i++;
                }
                return(temp.Value);
            }

            set
            {
                if (index < StartIndex || index >= Count + StartIndex)
                {
                    throw new IndexOutOfRangeException();
                }
                int i = StartIndex;
                IndexArrayElement <T> temp = head;
                while (i != index)
                {
                    temp = temp.Next;
                    i++;
                }

                temp.Value = value;
            }
        }
Beispiel #3
0
        public void RemoveAt(int index)
        {
            if (index < StartIndex || index >= Count + StartIndex)
            {
                throw new IndexOutOfRangeException();
            }
            int i = StartIndex;

            if (i == index)
            {
                head = head.Next;
                Count--;
                return;
            }

            IndexArrayElement <T> temp = head;

            while (i != index - 1)
            {
                temp = temp.Next;
                i++;
            }

            temp.Next = temp.Next.Next;
            Count--;
        }
Beispiel #4
0
        public bool Remove(T item)
        {
            if (item == null)
            {
                throw new ArgumentNullException();
            }
            IndexArrayElement <T> temp = head;

            if (head.Value.Equals(item))
            {
                head = head.Next;
                Count--;
                return(true);
            }
            while (temp.Next != null && !temp.Next.Value.Equals(item))
            {
                temp = temp.Next;
            }
            if (temp.Next != null)
            {
                temp.Next = temp.Next.Next;
                Count--;
                return(true);
            }
            return(false);
        }
Beispiel #5
0
 public IndexArray(int start, T[] array)
 {
     StartIndex = start;
     head       = null;
     for (int i = 0; i < array.Length; i++)
     {
         Add(array[i]);
     }
 }
Beispiel #6
0
 public void Clear()
 {
     if (head == null)
     {
         return;
     }
     else
     {
         while (head != null)
         {
             head = head.Next;
             Count--;
         }
     }
 }
Beispiel #7
0
 public void Add(T item)
 {
     if (head == null)
     {
         head = new IndexArrayElement <T>(item);
     }
     else
     {
         IndexArrayElement <T> temp = head;
         while (temp.Next != null)
         {
             temp = temp.Next;
         }
         temp.Next = new IndexArrayElement <T>(item);
     }
     Count++;
 }
Beispiel #8
0
        public bool Contains(T item)
        {
            if (item == null)
            {
                throw new ArgumentNullException();
            }
            IndexArrayElement <T> temp = head;

            while (temp != null)
            {
                if (temp.Value.Equals(item))
                {
                    return(true);
                }
                temp = temp.Next;
            }
            return(false);
        }
Beispiel #9
0
        public int IndexOf(T item)
        {
            if (item == null)
            {
                throw new ArgumentNullException();
            }
            int index = StartIndex;
            IndexArrayElement <T> temp = head;

            while (temp != null)
            {
                if (temp.Value.Equals(item))
                {
                    return(index);
                }
                temp = temp.Next;
                index++;
            }
            return(-1);
        }
Beispiel #10
0
        public void CopyTo(T[] array, int arrayIndex)
        {
            if (array == null)
            {
                throw new ArgumentNullException("The array cannot be null.");
            }
            if (arrayIndex < 0)
            {
                throw new ArgumentOutOfRangeException("The starting array index cannot be negative.");
            }
            if (Count > array.Length - arrayIndex + 1)
            {
                throw new ArgumentException("The destination array has fewer elements than the collection.");
            }

            IndexArrayElement <T> temp = head;
            int i = 0;

            while (temp != null)
            {
                array[i + arrayIndex] = temp.Value;
                temp = temp.Next;
            }
        }
Beispiel #11
0
 public IndexArrayElement(T value)
 {
     this.Value = value;
     Next       = null;
 }
Beispiel #12
0
 public IndexArrayElement()
 {
     Value = default(T);
     Next  = null;
 }
Beispiel #13
0
 public IndexArray(int start)
 {
     StartIndex = start;
     head       = null;
 }
Beispiel #14
0
 public IndexArray()
 {
     head       = null;
     StartIndex = 0;
 }