/// <summary> /// Enqueue /// </summary> /// <param name="data"></param> public void Enqueue(T data) { if (_list.IsEmpty()) { _list.InsertionInAnEmptyList(new LinkedListNode <T>(data)); return; } _list.InsertionAtTheEndOfTheList(new LinkedListNode <T>(data)); }
public void EmptyFlagFalseInNonEmptyLinkedList() { var list = new DoubleEndedLinkedList <int>(); list.PushBack(4); Assert.IsFalse(list.IsEmpty()); }
public void TestClear() { var list = new DoubleEndedLinkedList <int>(); list.PushBack(5); list.PushBack(-4); list.Clear(); Assert.AreEqual(0, list.Size); Assert.True(list.IsEmpty()); }
public void TestPopBack() { var list = new DoubleEndedLinkedList <int>(); int[] values = { -4, 3, 5, -6, 3, 5, -20, 0 }; // Push the items from 'values' array to the list foreach (int val in values) { list.PushBack(val); } // Repeatedly call PopBack until list gets empty int i = values.Length - 1; int expected_size = values.Length; while (!list.IsEmpty()) { Assert.AreEqual(expected_size--, list.Size); Assert.AreEqual(values[i--], list.PopBack()); } }
public void TestRemove() { // The first array in the tuple represents the contents of // the list before calling 'Remove', the second array is // the list after calling 'Remove'. The third element of // the tuple represents the value to be removed from the // list. Tuple <int[], int[], int>[] test_vectors = { new Tuple <int[], int[], int>( new int[] { }, new int[] { }, 5), new Tuple <int[], int[], int>( new int[] { -2, 9, 0 }, new int[] { -2, 9, 0 }, 6), new Tuple <int[], int[], int>( new int[] { 6 }, new int[] { }, 6), new Tuple <int[], int[], int>( new int[] { -2, 5, 0 }, new int[] { -2, 0 }, 5), new Tuple <int[], int[], int>( new int[] { 4, 4,4, 4, 4 }, new int[] { }, 4), new Tuple <int[], int[], int>( new int[] { -3, 5,6, 7, -3 }, new int[] { 5, 6, 7 }, -3), new Tuple <int[], int[], int>( new int[] { 10, 2,5, 6, 2, 2, 2 }, new int[] { 10, 5, 6 }, 2), new Tuple <int[], int[], int>( new int[] { -1, 0,0, 5, -1, 9 }, new int[] { 0, 0,5, 9 }, -1), }; foreach (Tuple <int[], int[], int> test_vector in test_vectors) { var list = new DoubleEndedLinkedList <int>(); // Populate the list with the items from Tuple.Item1 foreach (int value in test_vector.Item1) { list.PushBack(value); } // Remove Tuple.Item3 value from the list list.Remove(test_vector.Item3); // Verify that the contents of the list is equal to Tuple.Item2 Assert.AreEqual(test_vector.Item2.Length, list.Size); int index = 0; foreach (int value in list) { Assert.AreEqual(test_vector.Item2[index++], value); } // Also verify that IsEmpty and Size return correct values Assert.AreEqual(test_vector.Item2.Length, list.Size); Assert.AreEqual(test_vector.Item2.Length == 0, list.IsEmpty()); // Finally, verify that PeakFront and PeakBack return expected // values if (!list.IsEmpty()) { Assert.AreEqual(test_vector.Item2[0], list.PeakFront()); Assert.AreEqual(test_vector.Item2[test_vector.Item2.Length - 1], list.PeakBack()); } } }
public void EmptyFlagTrueInEmptyLinkedList() { var list = new DoubleEndedLinkedList <int>(); Assert.IsTrue(list.IsEmpty()); }