Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void SredniaLiniowe(int dlugosc)
- {
- int[] y = new int[dlugosc];
- for (int i = 1; i < dlugosc; i++)
- {
- y[i] = i;
- }
- int dzielenie = dlugosc*1/2;
- int srednia = dzielenie + 1 / 2;
- Console.WriteLine("Średni wynik dla "+dlugosc+ "elementów to " + srednia);
- }
- static void SredniaBinarnie(int dlugosc)
- {
- int[] y = new int[dlugosc];
- for (int i = 1; i < dlugosc; i++)
- {
- y[i] = i;
- }
- int lewo = 0, prawo = y.Length - 1, srodek, kroki = 0;
- while (lewo <= prawo)
- {
- kroki++;
- srodek = (lewo + prawo) / 2;
- if (y[srodek] == dlugosc) break;
- else if (y[srodek] > dlugosc) prawo = srodek - 1;
- else lewo = srodek + 1;
- }
- Console.WriteLine("Dla "+dlugosc+ "elementów, średni czas wykonania to " + Math.Log(y.Length).ToString("F0"));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement