usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Threading;//used to include sleepnamespaceBubble Sort {classProgram {Static voidMain (string[] args) { int[] array=New int[Ten]; intExchange; for(intI=0; I<array. length;i++)//length is 10, why not fill 10 directly{Random ran=NewRandom ();//The default seed is the time, not the rest, equals the default seed is a time, and therefore grows into a random numberArray[i]=ran. Next (0, -); Thread.Sleep ( -); } console.write ("The resulting random sequence is:"); foreach(intXinchArray) Console.Write (" "+x); for(intI=0;i<9; i++)//The adjacent numbers are sorted in size, the extreme is the maximum number in the smallest position, so that the adjacent position can be exchanged 9 times to move it to its rightful place. { for(intK =0; K <9; k++) { if(Array[k] >= array[k +1]) {Exchange=Array[k]; ARRAY[K]= Array[k +1]; Array[k+1] =Exchange; }}} Console.WriteLine (); Console.Write ("the sorted sequence is:"); foreach(intYinchArray) Console. Write (" "+y); Console.Write ("\ n Please enter the number to ask for the query:"); intnum =int. Parse (Console.ReadLine ()); intBegin =0, end =9, Mid; BOOLAbc=Array. Contains (num); if(abc==false) Console.WriteLine ("This number is not included in the sequence.");//used a Boolean type, not too skilled Else while(true) {Mid= (begin + END)/2; if(Array[mid] >num) End=mid; if(Array[mid] <num) begin=mid; if(Array[mid] = =num) {Console.WriteLine ("The number you are looking for is indexed in the column"+mid); Break; }} console.readline (); } }}
Find a location using the binary lookup method after bubbling sorting