0
public void Insert(int index, T element)
    {
        if (Count == Capacity) ExtendData(DEFAULT_CAPACITY);

        if (index == Count)

        {

            data[Count++] = element;

            return;

        }

        if (index > Count || index < 0)
            throw new NotImplementedException();

        int count = Count;
        while (count != index)
        {
            data[count] = data[count - 1];
            count--;
        }
        data[count] = element;
        Count++;

    }

I am using this method to insert elements at specific indexes. But, when I do Insert number -1 at index 'vector.Count+1', I am getting Last operation is invalid and must throw IndexOutOfRangeException. Your solution does not match specification.

Felix
  • 7,790
  • 10
  • 53
  • 82

0 Answers0