In the Pang Maogo teacher's courseware, there are a lot of specific algorithm examples, here, tracking gives, the binary method to find the specified number of code:
- Implementing the Environment: Ubuntu 17.4 under VMware
- Compilation environment: Comes with a compiler.
Below is the procedure for compiling the environment under Ubuntu:
- Press "ALT" + "CRTL" + "T" at the same time to eject the terminal interface
- Create: Command gedit main.c gedit Create a C file with the name main
- Edit: Command Gtouch main.c pop-up text box for editing
- Compile: "ALT" + "F4" to turn off the text box, enter the terminal interface, command GCCMAIN.C to compile, if there is no error, the next command prompt g++ is the C + + file compilation
- Result:./a.out to view
Here is an example of a simple dichotomy lookup:
1#include <stdio.h>2 Main ()3 {4 intnum[]={1,2,3,4,5,6,7,8,9,Ten};5 intleft=0, right=9, A;6 intfind;7scanf"%d",&find);8 while(left<Right )9 {TenA= (left+right)/2; One if(num[a]==find) A { -printf"The number you are looking for is in the first%d", A +1); - Break; the } - Else if(find>Num[a]) -left=a+1; - Else +right=a-1; - } + if(left<Right ) Aprintf"without this number"); at}
C-Language dichotomy finds the specified number in a series