// does LL store largest int32 public void StoreLargestInt32() { IntLinkedList myLL = new IntLinkedList(); myLL.InsertAtFront(Int32.MaxValue); int actual = myLL.RemoveFromFront(); Assert.AreEqual <int>(2147483647, actual); }
public void AddRange(IntLinkedList Values) { IntLinkedItem item = Values.firstItem; while (item != null) { Add(item.Value); item = item.NextItem; } }
public void IsEmptyLLafterAddAndRemove() { IntLinkedList myLL = new IntLinkedList(); myLL.InsertAtFront(111); myLL.InsertAtFront(222); myLL.RemoveFromFront(); myLL.RemoveFromFront(); myLL.RemoveFromFront(); }
public void ReturnCountWhenListHasItems() { IntLinkedList list = new IntLinkedList(); list.Add(8); list.Add(13); list.Add(21); Assert.Equal(3, list.Count); }
// does LL store negative numbers public void StoreNegativeNumbers() { IntLinkedList myLL = new IntLinkedList(); int total = 0; myLL.InsertAtFront(-111); myLL.InsertAtFront(-222); total = total + myLL.RemoveFromFront(); total = total + myLL.RemoveFromFront(); Assert.AreEqual <int>(-333, total); }
// does LL hold data correctly, and in the correct order // insert 3 values at top, remove 2 from top, total should be = val of the last two added public void StoreAndRetrieveFromTop() { IntLinkedList myLL = new IntLinkedList(); int total = 0; myLL.InsertAtFront(111); myLL.InsertAtFront(222); myLL.InsertAtFront(333); total = total + myLL.RemoveFromFront(); total = total + myLL.RemoveFromFront(); Assert.AreEqual <int>(555, total); }
public static int[] SortWithoutGenerics(int[] Values) { IntLinkedList Original = new IntLinkedList(); IntLinkedList Result = new IntLinkedList(); IntLinkedList Sublist = new IntLinkedList(); Original.AddRange(Values); //While we still have numbers to sort while (Original.Count > 0) { //Clear sublist and take first available number from original to the new sublist Sublist.Clear(); Sublist.Add(Original.FirstItem.Value); Original.Remove(Original.FirstItem); IntLinkedItem currentOriginalItem = Original.FirstItem; //Iterate through original numbers while (currentOriginalItem != null) { //If the number is bigger than the last item in the sublist if (currentOriginalItem.Value > Sublist.LastItem.Value) { //Add it to the sublist and remove it from original Sublist.Add(currentOriginalItem.Value); //Store the next item IntLinkedItem nextItem = currentOriginalItem.NextItem; //Remove current item from original Original.Remove(currentOriginalItem); //Set next item as current item currentOriginalItem = nextItem; } currentOriginalItem = currentOriginalItem.NextItem; } //If this is the first sublist if (Result.Count == 0) { Result.AddRange(Sublist); //Add all the numbers to the result } else { IntLinkedItem currentSublistItem = Sublist.FirstItem; //Iterate through the sublist while (currentSublistItem != null) { bool inserted = false; IntLinkedItem currentResultItem = Result.FirstItem; //Iterate through the current result while (currentResultItem != null) { //Is the sublist number lower than the current item from result? if (currentSublistItem.Value < currentResultItem.Value) { //Yes, insert it at the current Result position Result.InsertBefore(currentResultItem, currentSublistItem.Value); inserted = true; break; } currentResultItem = currentResultItem.NextItem; } //Did we inserted the item because found it was lower than one of the result's number? if (!inserted) { Result.Add(currentSublistItem.Value); //No, we add it to the end of the results } currentSublistItem = currentSublistItem.NextItem; } } } //Return the results return(Result.ToArray()); }
public void RemoveFromEmptyLL() { IntLinkedList myLL = new IntLinkedList(); myLL.RemoveFromFront(); }
public void ReturnZeroWhenListIsEmpty() { IntLinkedList list = new IntLinkedList(); Assert.Equal(0, list.Count); }
static void Main(string[] args) { { IEnumerable <int> sequence = new IntLinkedList(10); foreach (int element in sequence) { Console.WriteLine(element); } } { IEnumerable <int> sequence = new IntLinkedList(); if (sequence.Count() == 0) { Console.WriteLine("IntLinkedList 0 count PASS"); } else { Console.WriteLine("IntLinkedList 0 count FAILED"); } } { IEnumerable <int> sequence = new IntLinkedList(5); if (sequence.Count() == 5) { Console.WriteLine("IntLinkedList fixed count PASS"); } else { Console.WriteLine("IntLinkedList fixed count FAILED"); } } { IEnumerable <int> sequence = new IntLinkedList(10).Take(5); if (sequence.Last() == 4 && sequence.Count() == 5) { Console.WriteLine("Nums take 5 PASS"); } else { Console.WriteLine("Nums take 5 FAILED"); } } //{ // ICollection<int> sequence = new List<int>(); // if (sequence.Count == 0) // { // Console.WriteLine("IntLinkedList 0 count PASS"); // } // else // { // Console.WriteLine("IntLinkedList 0 count FAILED"); // } //} //{ // ICollection<int> sequence = Enumerable.Range(0, 5).ToList(); // if (sequence.Count == 5) // { // Console.WriteLine("IntLinkedList fixed count PASS"); // } // else // { // Console.WriteLine("IntLinkedList fixed count FAILED"); // } //} //{ // ICollection<int> sequence = Enumerable.Range(0, 5).ToList(); // sequence.Remove(4); // if (sequence.Count == 4) // { // Console.WriteLine("IntLinkedList remove one PASS"); // } // else // { // Console.WriteLine("IntLinkedList remove one FAILED"); // } //} //{ // ICollection<int> sequence = Enumerable.Range(0, 5).ToList(); // sequence.Add(5); // if (sequence.Count == 6) // { // Console.WriteLine("IntLinkedList add one PASS"); // } // else // { // Console.WriteLine("IntLinkedList add one FAILED"); // } //} }