public class Tester {
        public static void main(String[] args) {
//              System.out.println(jeUsporiadane(new int[]{3,2,3,4}));
                BubbleSort bs = new BubbleSort();
                bs.utried(new int[]{1,2,3,5,4});
                bs.vypisPole();
                SelectionSort ss = new SelectionSort();
                ss.utried(new int[]{5,4,3,2,1});
                ss.vypisPole();
        }
        public static boolean jeUsporiadane(int[] p) {
                for (int i = 0; i < p.length-1; i++) {
                        if(p[i]>p[i+1]) return false;
                }
                return true;
    }
/* ALTERNATIVA
        public static boolean jeUsporiadane(int[] p) {
                int iterator = 0;
                while ((iterator < p.length - 1) && (p[iterator] <= p[iterator + 1])) {
                        iterator++;
                }
                if (iterator == (p.length - 1))
                        return true;
                return false;
        }
*/
        public static int binarneHladajIndex(int[] p, int hodnota) {
                int odIndex = 0;
                int doIndex = p.length - 1;
                int stredIndex = 0;
                while (doIndex - odIndex >= 1) {
                        stredIndex = (odIndex+doIndex) /2;
                        if(p[stredIndex]==hodnota) {
                                return stredIndex;
                        } else if (p[stredIndex]<hodnota) {
                                odIndex = stredIndex+1; 
                        } else {
                                doIndex = stredIndex - 1;
                        }
                }
                if (p[stredIndex + 1] == hodnota) {
                        return stredIndex + 1;
                }
                return -1;
        }
}