Beispiel #1
0
        public void AddTest()
        {
            CyclicList <int> c = new CyclicList <int>();

            c.Add(1);
            c.Add(2);
            c.Add(3);
        }
Beispiel #2
0
        public void RemoveTest()
        {
            CyclicList <int> c = new CyclicList <int>();

            c.Add(1);
            c.Add(2);
            c.Add(3);

            c.Remove(1);

            Assert.AreEqual(c[0], 1);
            Assert.AreEqual(c[1], 3);
            Assert.AreEqual(c[2], 1);
            Assert.AreEqual(c[3], 3);
        }
Beispiel #3
0
        public void GetTest()
        {
            CyclicList <int> c = new CyclicList <int>();

            c.Add(1);
            c.Add(2);
            c.Add(3);


            Assert.AreEqual(c[0], 1);
            Assert.AreEqual(c[1], 2);
            Assert.AreEqual(c[2], 3);
            Assert.AreEqual(c[3], 1);
            Assert.AreEqual(c[4], 2);
            Assert.AreEqual(c[5], 3);
        }
Beispiel #4
0
        public void HeadRemovalTest()
        {
            CyclicList <int> c = new CyclicList <int>();

            c.Add(1);
            c.Add(2);
            c.Add(3);

            c.Remove(0);
            Debug.WriteLine(c[0].ToString() + c[1].ToString() + c[2].ToString());

            Assert.AreEqual(c[0], 2);
            Assert.AreEqual(c[1], 3);
            Assert.AreEqual(c[2], 2);
            Assert.AreEqual(c[3], 3);

            c.Remove(0);
            Assert.AreEqual(3, c[0]);
            c.Remove(0);
            Assert.ThrowsException <Exception>(() => { Debug.WriteLine(c[0]); });
        }
Beispiel #5
0
 public static int Process(int N, int M)
 {
     CyclicList lst = new CyclicList();
     ListElement<int> pt = new ListElement<int>(0);
     lst.Add(pt, pt);
     for (int i = 1; i < N; i++)
     {
         var tm = new ListElement<int>(i);
         lst.Add(tm, pt);
         pt = tm;
     }
     ListElement<int> el = pt;
     while (el.Next != el)
     {
         for (int i = 0; i < M; i++)
         {
             el = el.Next;
         }
         Console.WriteLine("Remove {0}", el.Next.Value);
         el.Next = el.Next.Next;
     }
     return el.Value;
 }
Beispiel #6
0
        public void Add(string message, Routine item)
        {
            Color c;

            if (_menuItems.Count == 0)
            {
                c = Color.White;
            }
            else
            {
                c = (_menuItems.Count % 2 == 1) ? Color.White:Color.Black;
            }
            var m = new MenuSelection(message, c, item);

            _menuItems.Add(m);
        }
 internal static void Distribute(Tape src, CyclicList<Tape> tapes)
 {
     //Log.WriteDistMessage("Dist start");
     tapes.Clean();
     string line;
     using (StreamReader reader = new StreamReader(src.FilePath))
         while ((line = reader.ReadLine()) != null)
         {
             int val = int.Parse(line);
             if (tapes.IsFirstRun() || val >= tapes.LastValue)
             {
                 tapes.Add(val);
                 //Log.WriteDistMessage("Adding " + val + " to " + tapes.Index + ".", 4);
             }
             else
             {
                 tapes.ChangeToNextAndAdd(val);
                 //Log.WriteInfoMessage("NIEPOSORTOWANE!" + val);
             }
             //Log.WriteDistMessage("Adding " + val + " to " + tapes.Index + ".", 4);
         }
     Log.WriteDistMessage("A: " + tapes[0].ShowFile());
     Log.WriteDistMessage("B: " + tapes[1].ShowFile());
     //Log.WriteDistMessage("Dist end");
 }