Find a location using the binary lookup method after bubbling sorting

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.