import java.util.Arrays;
public class BinVyhladavanie {
/**
* @param args
*/
public static void main(String[] args) {
int[] p = new int[]{1,2,6,4,5,3,7,9,8,10};
// for (int i = 1; i < p.length+1; i++) {
// System.out.println(binarneHladajIndex(p, i));
// }
//System.out.println(binarneHladajIndex(p, 10));
bubbleSort(p);
}
public static int binarneHladajIndex(int[] p, int hodnota) {
int odIdx = 0;
int poIdx = p.length - 1;
// poIdx - odIdx >= 0
while(odIdx <= poIdx){
int stredIdx = (odIdx + poIdx) / 2;
if (hodnota > p[stredIdx]) {
odIdx = stredIdx + 1;
}
if (hodnota < p[stredIdx]){
poIdx = stredIdx - 1;
}
if (hodnota == p[stredIdx]){
return stredIdx;
}
}
return -1;
}
private static void bubbleSort(int[] p) {
for (int i = 0; i < p.length; i++) {
for (int j = i+1; j < p.length; j++) {
if(p[i]>p[j]) {
int pom = p[j];
p[j] = p[i];
p[i] = pom;
}
}
}
System.out.println(Arrays.toString(p));
}
}