Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- class Program
- {
- private static readonly Random Random = new Random();
- public static void Main()
- {
- int[] array = GenerateArray(100);
- long timeStart = DateTime.Now.Ticks / 10000;
- BubbleSort(array);
- Console.WriteLine("Время в миллисекундах после сортировки массива " + (DateTime.Now.Ticks / 10000 - timeStart));
- timeStart = DateTime.Now.Ticks / 10000;
- UnElementsInArray(array);
- Console.WriteLine("Время в миллисекундах после поиска количества чётных чисел в массиве " +
- (DateTime.Now.Ticks / 10000 - timeStart));
- Console.WriteLine();
- int findElem = GetElemReadLine(array.Length);
- timeStart = DateTime.Now.Ticks / 10000;
- SearchInMassive(array, findElem);
- Console.WriteLine("Время в миллисекундах работы алгоритма " + (DateTime.Now.Ticks / 10000 - timeStart));
- }
- private static void BubbleSort(int[] array)
- {
- for (int i = 0; i < array.Length; i++)
- for (int j = 0; j < array.Length - 1; j++)
- if (array[j] > array[j + 1])
- {
- int t = array[j + 1];
- array[j + 1] = array[j];
- array[j] = t;
- }
- }
- private static int GetElemReadLine(int arrayLength)
- {
- Console.WriteLine("Вводи индекс для поиска");
- int resElem;
- bool readedLine = false;
- do
- {
- if(readedLine)
- Console.WriteLine("ъуъ, давай поадекватнее индекс");
- readedLine = true;
- resElem = int.Parse(Console.ReadLine());
- } while (resElem < 0 || resElem >= arrayLength);
- return resElem;
- }
- private static int[] GenerateArray(int length)
- {
- var array = new int[length];
- for (int i = 0; i < array.Length; i++)
- array[i] = Random.Next();
- return array;
- }
- private static void UnElementsInArray(int[] array)
- {
- int unElements = 0;
- foreach (int e in array)
- {
- if (e % 2 == 0)
- {
- unElements++;
- }
- }
- Console.WriteLine($"Количество чётных чисел {unElements}");
- }
- private static void SearchInMassive(int[] array, int findElem)
- {
- int indexOfMassive = findElem;
- Console.WriteLine();
- Console.WriteLine(array[indexOfMassive]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement