Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BinarySearch/.idea/description.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions BinarySearch/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions BinarySearch/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions BinarySearch/.idea/project-template.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

205 changes: 205 additions & 0 deletions BinarySearch/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions BinarySearch/BinarySearch.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Binary file not shown.
26 changes: 26 additions & 0 deletions BinarySearch/src/alexrm84/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package alexrm84;

public class Main {

public static void main(String[] args) {
int massSize=10000;
int[] mass = new int[massSize];
for (int i = 0; i < massSize; i++) {
mass[i]=i+5;
}
System.out.println("Индекс искомова числа= "+findNumber(mass,0,massSize-1,11,1));
}

public static int findNumber(int[] mass, int min, int max, int needN, int count){
if (mass[(min+max)/2]==needN) {
System.out.println("Количество проверок= "+count);
return (min+max)/2;
}
if (min>max) return -1;
if (mass[(min+max)/2]<needN) {
return findNumber(mass,(min+max)/2+1,max,needN,count+1);
} else {
return findNumber(mass, min, (min+max)/2-1,needN,count+1);
}
}
}