public void InsertItemAtIndex()
        {
            userArray.Insert(15, 0);
            Assert.AreEqual(1, userArray.count);
            Assert.AreEqual(16, userArray.capacity);
            Assert.AreEqual(15, userArray.GetItem(0));

            userArray.Insert(13, 1);
            Assert.AreEqual(2, userArray.count);
            Assert.AreEqual(16, userArray.capacity);
            Assert.AreEqual(13, userArray.GetItem(1));

            userArray.Append(23);
            userArray.Append(77);
            userArray.Append(11);
            userArray.Append(77);
            userArray.Append(11);
            userArray.Append(23);
            userArray.Append(77);
            userArray.Append(11);
            userArray.Append(77);
            userArray.Append(11);
            userArray.Append(77);
            userArray.Append(10);

            userArray.Insert(335, 10);
            userArray.Insert(335, 10);
            userArray.Insert(66, 1);
            Assert.AreEqual(17, userArray.count);
            Assert.AreEqual(32, userArray.capacity);
            Assert.AreEqual(10, userArray.GetItem(16));
        }
Пример #2
0
 public void Push(T val)
 {
     if (val == null)
     {
         return;
     }
     dyn.Insert(val, 0);
 }
Пример #3
0
        public static void Main(String[] args)
        {
            DynArray <int> dya = new DynArray <int>();

            for (int i = 0; i < 16; i++)
            {
                dya.Append(i);
            }

            dya.Insert(100, 15);
        }
Пример #4
0
        static void TestInsert()
        {
            Console.WriteLine("test insert");
            Console.WriteLine();

            var dynamicArray = new DynArray <int>();

            Console.WriteLine("array count = " + dynamicArray.count);
            Console.WriteLine("array capacity = " + dynamicArray.capacity);

            for (var i = 0; i < dynamicArray.capacity - 3; i++)
            {
                dynamicArray.Append(i * i);
            }

            for (var i = 0; i < dynamicArray.count; i++)
            {
                Console.Write(dynamicArray.GetItem(i) + " ");
            }

            Console.WriteLine();
            Console.WriteLine("insert 1000 into 0");
            Console.WriteLine("array count before = " + dynamicArray.count);
            Console.WriteLine("array capacity before = " + dynamicArray.capacity);
            dynamicArray.Insert(1000, 0);
            Console.WriteLine("array count after = " + dynamicArray.count);
            Console.WriteLine("array capacity after = " + dynamicArray.capacity);

            for (var i = 0; i < dynamicArray.count; i++)
            {
                Console.Write(dynamicArray.GetItem(i) + " ");
            }

            Console.WriteLine(Environment.NewLine);
            Console.WriteLine("insert 1000 into 7");
            Console.WriteLine("array count before = " + dynamicArray.count);
            Console.WriteLine("array capacity before = " + dynamicArray.capacity);
            dynamicArray.Insert(7000, 7);
            Console.WriteLine("array count after = " + dynamicArray.count);
            Console.WriteLine("array capacity after = " + dynamicArray.capacity);

            for (var i = 0; i < dynamicArray.count; i++)
            {
                Console.Write(dynamicArray.GetItem(i) + " ");
            }


            Console.WriteLine(Environment.NewLine);
            Console.WriteLine("insert 15000 into 15");
            Console.WriteLine("array count before = " + dynamicArray.count);
            Console.WriteLine("array capacity before = " + dynamicArray.capacity);
            dynamicArray.Insert(15000, 15);
            Console.WriteLine("array count after = " + dynamicArray.count);
            Console.WriteLine("array capacity after = " + dynamicArray.capacity);

            for (var i = 0; i < dynamicArray.count; i++)
            {
                Console.Write(dynamicArray.GetItem(i) + " ");
            }


            Console.WriteLine(Environment.NewLine);
            Console.WriteLine("insert 15000 into 15");
            Console.WriteLine("array count before = " + dynamicArray.count);
            Console.WriteLine("array capacity before = " + dynamicArray.capacity);
            dynamicArray.Insert(15000, 15);
            Console.WriteLine("array count after = " + dynamicArray.count);
            Console.WriteLine("array capacity after = " + dynamicArray.capacity);

            Console.WriteLine();
            Console.WriteLine("try to insert -100 into " + (dynamicArray.count + 1));
            try
            {
                dynamicArray.Insert(-100, dynamicArray.count + 1);
            }
            catch (IndexOutOfRangeException)
            {
                Console.WriteLine("exception OutOfRange");
            }

            Console.WriteLine(new string('=', 30));
        }