Beispiel #1
0
        static void TestRemove()
        {
            Console.WriteLine("test count");
            var dynamicArray = new DynArray <int>();

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

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

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

            Console.WriteLine();
            Console.WriteLine("Remove items");
            for (var i = 20; i > 4; i--)
            {
                dynamicArray.Remove(i);
            }

            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();
            Console.WriteLine("Remove items");
            for (var i = dynamicArray.count - 2; i > 4; i--)
            {
                dynamicArray.Remove(i);
            }

            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();
            Console.WriteLine("try to delete at " + (dynamicArray.count + 1));
            try
            {
                dynamicArray.Remove(dynamicArray.count + 1);
            }
            catch (IndexOutOfRangeException)
            {
                Console.WriteLine("exception OutOfRange");
            }
        }
        public void RemoveItemByIndex()
        {
            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.Append(23);
            userArray.Append(77);
            userArray.Append(11);
            userArray.Append(77);
            userArray.Append(11);
            userArray.Append(77);
            userArray.Append(10);
            Assert.AreEqual(32, userArray.capacity);
            Assert.AreEqual(19, userArray.count);

            userArray.Remove(0);
            Assert.AreEqual(32, userArray.capacity);
            Assert.AreEqual(18, userArray.count);

            userArray.Remove(17);
            Assert.AreEqual(32, userArray.capacity);
            Assert.AreEqual(17, userArray.count);

            userArray.Remove(13);
            Assert.AreEqual(32, userArray.capacity);
            Assert.AreEqual(16, userArray.count);

            userArray.Remove(12);
            Assert.AreEqual(21, userArray.capacity);
            Assert.AreEqual(15, userArray.count);

            userArray.Remove(12);
            userArray.Remove(12);
            userArray.Remove(12);
            userArray.Remove(12);
            Assert.AreEqual(21, userArray.capacity);
            Assert.AreEqual(11, userArray.count);

            userArray.Remove(0);
            Assert.AreEqual(16, userArray.capacity);
            Assert.AreEqual(10, userArray.count);
        }
Beispiel #3
0
 public T Pop()
 {
     if (dyn.count > 0)
     {
         T val = dyn.GetItem(0);
         dyn.Remove(0);
         if (dyn.count == 0)
         {
             return(val);
         }
         return(val);
     }
     return(default(T));
 }