예제 #1
0
 void Start()
 {
     stack = new MyStack <int>();
     stack.Add(1);
     stack.Add(3);
     stack.Add(2);
     foreach (var i in stack)
     {
         print(i + " ");
     }
 }
예제 #2
0
 /// <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());
 }
예제 #3
0
        static (int, long, TimeSpan, bool) test_stack(int _len)
        {
            MyStack.N_op = 0;
            int max = _len;

            int[] sh_ar = get_shuffled_array(_len, max);


            //long ellapledTicks = DateTime.Now.Ticks;
            TimeSpan Time1 = DateTime.Now.TimeOfDay;



            MyStack stack = new MyStack(_len);

            for (int i = 0; i < sh_ar.Length; i++)
            {
                stack.Add(sh_ar[i]);
            }


            stack.quicksort(0, stack.TopPointer - 1);


            //ellapledTicks = DateTime.Now.Ticks - ellapledTicks;
            TimeSpan Time2       = DateTime.Now.TimeOfDay;
            TimeSpan time_result = Time2 - Time1;

            long N_op    = MyStack.N_op;
            bool success = is_stack_sorted(stack.GetCopy());

            return(_len, N_op, time_result, success);
        }
예제 #4
0
        public void Adds_Single_Item()
        {
            var stack = new MyStack <int>();

            stack.Add(1);

            Assert.IsTrue(stack.Count == 1);
        }
예제 #5
0
        public void TestMethodStack7()
        {
            //Arrange
            int[]         arr = new int[] { 1, 2, 3, 4 };
            MyStack <int> s   = new MyStack <int>(arr);

            //Act
            s.Add(3);
            //Assert
            Assert.IsTrue(s.Count() == 5);
        }