Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. Zakładam że funkcja main pokazuje jakie ma być użycie danej metody.
  2.  
  3. W pierwszej kolejności powinno być sprawdzenie czy tablica jest dłuższa niż zero bo inaczej metoda bedziee się wykonywac w nieskńczoność.
  4. Po drugie metoda nie znajdzie przypadku w którym najmniejsza liczba jest na perwszym miejscu.
  5. Po trzecie nie ma sprawdzenia czy argument x nie jest większy niz długość tablicy.
  6.  
  7. Poniżej moja implementacja funkcji Mini tylko że ją wywołuje isę po przez: Mini2(tab, tab.Length - 1);
  8.  
  9. static int Mini2(int[] table, int currentPosition)
  10. {
  11. if (currentPosition < 0 || currentPosition >= table.Length)
  12. throw new ArgumentOutOfRangeException("currentPosition");
  13.  
  14. if (currentPosition == 0) return table[0];
  15.  
  16. return Math.Min(
  17. table[currentPosition],
  18. Mini2(table,currentPosition - 1));
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement