示例#1
0
        static void Search(TestCollections test, Diesel element)
        {
            Stopwatch SW = new Stopwatch();


            SW.Restart();
            test.stackEng.Contains(element.BaseEngine());
            SW.Stop();
            long timeStackEng = SW.Elapsed.Ticks;

            SW.Restart();
            test.stackStr.Contains(element.ToString());
            SW.Stop();
            long timeStackStr = SW.Elapsed.Ticks;

            SW.Restart();
            test.dictEng.ContainsKey(element.BaseEngine());
            SW.Stop();
            long timeDictEng = SW.Elapsed.Ticks;

            SW.Restart();
            test.dictStr.ContainsKey(element.ToString());
            SW.Stop();
            long timeDictStr = SW.Elapsed.Ticks;

            Console.WriteLine($"Stack:{timeStackEng} (в тиках)");
            Console.WriteLine($"Stack<str>:{timeStackStr} (в тиках)");
            Console.WriteLine($"Dictionary:{timeDictEng} (в тиках)");
            Console.WriteLine($"Dictionary<str>:{timeDictStr} (в тиках)");
        }
示例#2
0
 static void FindMatch(Dictionary <int, Engine> collection, Diesel eng)
 {
     if (collection.Values.Contains(eng))
     {
         Console.WriteLine($"Элемент найден");
     }
     else
     {
         Console.WriteLine($"Элемент не найден");
     }
 }
示例#3
0
 public void WriteDict()
 {
     Console.WriteLine("dictionary");
     foreach (KeyValuePair <Engine, Diesel> keyValue in dictEng)
     {
         Diesel eng = keyValue.Value as Diesel;
         if (eng != null)
         {
             Console.WriteLine(eng.ToString());
         }
     }
 }
示例#4
0
 public TestCollections(int size)
 {
     Size = size;
     for (int i = 0; i < size; i++)
     {
         Diesel dies = new Diesel();
         dies = dies.MakeRandom();
         stackEng.Push(dies.BaseEngine());
         stackStr.Push(dies.ToString());
         dictEng.Add(dies.BaseEngine(), dies);
         dictStr.Add(dies.ToString(), dies);
     }
 }
示例#5
0
        static int AmountOf2Stroke(Queue collection)
        {
            int count = 0;

            foreach (object elem in collection)
            {
                Diesel someEng = elem as Diesel;
                if (someEng != null && someEng.NumOfStroke == 2)
                {
                    count++;
                }
            }
            return(count);
        }
示例#6
0
        static int AmountOf2Stroke(Dictionary <int, Engine> collection)
        {
            int count = 0;

            foreach (KeyValuePair <int, Engine> elem in collection)
            {
                Diesel someEng = elem.Value as Diesel;
                if (someEng != null && someEng.NumOfStroke == 2)
                {
                    count++;
                }
            }

            return(count);
        }
示例#7
0
        static int AmountOfDies(Queue collection)
        {
            int count = 0;

            foreach (object elem in collection)
            {
                Diesel someEng = elem as Diesel;
                if (someEng != null)
                {
                    count++;
                }
            }

            return(count);
        }
示例#8
0
        public void Add()
        {
            Console.WriteLine("Введите имя");
            string name = Console.ReadLine();

            Console.WriteLine("Введите мощность");
            int num = InputNum(9999);

            Console.WriteLine("Введите количество тактов: 4 или 2");
            int stroke = InputNum(4);

            Diesel dies = new Diesel(name, num, stroke);

            stackEng.Push(dies.BaseEngine());
            stackStr.Push(dies.ToString());
            dictEng.Add(dies.BaseEngine(), dies);
            dictStr.Add(dies.ToString(), dies);
            Console.WriteLine("Добавлено");
            Size++;
        }
示例#9
0
        static void Test(TestCollections test)
        {
            Diesel first  = null;
            Diesel middle = null;
            Diesel last   = null;
            int    num    = 0;

            foreach (KeyValuePair <Engine, Diesel> elem in test.dictEng)
            {
                if (num == 0)
                {
                    first = (Diesel)elem.Value.Clone();
                }
                if (num == (int)test.Size / 2)
                {
                    middle = (Diesel)elem.Value.Clone();
                }
                if (num == test.Size - 1)
                {
                    last = (Diesel)elem.Value.Clone();
                }
                num++;
            }


            Console.WriteLine("Поиск первого:");
            Search(test, first);
            Console.WriteLine();

            Console.WriteLine("Поиск среднего:");
            Search(test, middle);
            Console.WriteLine();

            Console.WriteLine("Поиск последнего:");
            Search(test, last);
            Console.WriteLine();
        }