/// <summary> /// Sorts the droids based on model /// </summary> /// <param name="toSort"></param> public void SortModel(List<Droid> toSort) { MyStack<UtilityDroid> utilityStack = new MyStack<UtilityDroid>(); MyStack<AstromechDroid> astroStack = new MyStack<AstromechDroid>(); MyStack<ProtocolDroid> protoStack = new MyStack<ProtocolDroid>(); MyStack<JanitorDroid> janitorStack = new MyStack<JanitorDroid>(); //Separates the List based on class foreach (Droid d in toSort) { if (d is AstromechDroid) astroStack.Add((AstromechDroid)d); else if (d is JanitorDroid) janitorStack.Add((JanitorDroid)d); else if (d is UtilityDroid) utilityStack.Add((UtilityDroid)d); else if (d is ProtocolDroid) protoStack.Add((ProtocolDroid)d); } // puts the stacks into a Queue MyQueue<Droid> tmpQue = new MyQueue<Droid>(); while (astroStack.Count > 0) tmpQue.Add(astroStack.Get()); while (janitorStack.Count > 0) tmpQue.Add(janitorStack.Get()); while (utilityStack.Count > 0) tmpQue.Add(utilityStack.Get()); while (protoStack.Count > 0) tmpQue.Add(protoStack.Get()); //Relies on the fact that a list is a reference object toSort.Clear(); while (tmpQue.Count > 0) toSort.Add(tmpQue.Get()); }
public void Returns_Last_Item() { var stack = new MyStack <int> { 1, 2, 3, 4, 5 }; int expected = 5; int actual = stack.Get(); Assert.AreEqual(expected, actual); }