Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Diagnostics;
- namespace ConsoleApp9
- {
- class Program
- {
- public static int OpAssignment;
- public static int OpComparisonLT;
- public static int OpIncrement;
- public static int OpComparisonEQ;
- static void Main(string[] args)
- {
- Console.WriteLine("Ilosc liniowa Czas");
- for(int i = 1; i<=10;i++)
- {
- wywolajLiniowa(26843545 * i);
- }
- Console.WriteLine("Ilosc binarna Czas");
- for (int i = 1; i<=10;i++)
- {
- wywolajBinarna(26843545 * i);
- }
- Console.ReadLine();
- }
- static void wywolajBinarna(int max_liczba)
- {
- int[] tablica_liczb = new int[max_liczba];
- for (int i = 0; i < max_liczba; i++)
- {
- tablica_liczb[i] = i;
- }
- IsPresentBinary(tablica_liczb, max_liczba - 1);
- liczCzasBinarny(tablica_liczb, max_liczba - 1);
- }
- static double liczSrednia(int[] Vector, int Number)
- {
- int suma = 0;
- for(int i = 0; i <= Vector.Length; i ++)
- {
- suma += i;
- }
- Console.WriteLine(suma +" "+ Vector.Length);
- double wynik = suma / Vector.Length;
- return wynik;
- }
- static bool IsPresentBinary(int[] Vector, int Number)
- {
- int Left = 0, Right = Vector.Length - 1, Middle;
- int licznik = 0;
- while (Left <= Right)
- {
- licznik++;
- Middle = (Left + Right) / 2;
- if (Vector[Middle] == Number)
- {
- Console.Write(licznik);
- return true;
- }
- else if (Vector[Middle] > Number) Right = Middle - 1;
- else Left = Middle + 1;
- }
- return false;
- }
- static void wywolajLiniowa(int max_liczba)
- {
- int[] tablica_liczb = new int[max_liczba];
- for (int i = 0; i < max_liczba; i++)
- {
- tablica_liczb[i] = i;
- }
- IsPresent(tablica_liczb,max_liczba - 1);
- liczCzasLiniowy(tablica_liczb,max_liczba - 1);
- }
- static bool IsPresent(int[] Vector, int Number)
- {
- OpAssignment = OpComparisonLT = 1;
- for (int i = 0; i <= Vector.Length; i++, OpIncrement++)
- {
- OpComparisonEQ++;
- if (Vector[i] == Number)
- {
- Console.Write(OpComparisonLT);
- return true;
- }
- OpComparisonLT++;
- }
- return false;
- }
- static bool liczCzasLiniowy(int[] Vector, int Number)
- {
- long StartingTime = Stopwatch.GetTimestamp();
- for (int i = 0; i <= Vector.Length; i++, OpIncrement++)
- {
- if (Vector[i] == Number)
- {
- long EndingTime = Stopwatch.GetTimestamp();
- Console.WriteLine(" "+liczCzas(StartingTime, EndingTime));
- return true;
- }
- }
- return false;
- }
- static bool liczCzasBinarny(int[] Vector, int Number)
- {
- int Left = 0, Right = Vector.Length - 1, Middle;
- long StartingTime = Stopwatch.GetTimestamp();
- while (Left <= Right)
- {
- Middle = (Left + Right) / 2;
- if (Vector[Middle] == Number)
- {
- long EndingTime = Stopwatch.GetTimestamp();
- Console.WriteLine(" " + liczCzas(StartingTime, EndingTime));
- return true;
- }
- else if (Vector[Middle] > Number) Right = Middle - 1;
- else Left = Middle + 1;
- }
- return false;
- }
- static double liczCzas(long StartingTime, long EndingTime)
- {
- long ElapsedTime = EndingTime - StartingTime;
- double ElapsedSeconds = ElapsedTime * (1.0 / Stopwatch.Frequency);
- return Math.Round(ElapsedSeconds,4);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement