[C/C ++] Bubble sorting and binary search, bubble binary

Source: Internet
Author: User

[C/C ++] Bubble sorting and binary search, bubble binary

Bubble Sorting: Compares two adjacent numbers. If a> B (or a <B) is used, the exchange value is used. Each time, the maximum (or minimum) value is pushed back.


Binary Search: Compare the value of a and B in the middle of each header and tail. If a> B indicates that the value of B is in front of the middle subscript, the head points to the first digit in the middle; if a <B indicates that the target value B is behind the intermediate subscript, the end is directed to the next digit of the intermediate downlink. If a = B, the intermediate subscript is returned. -1 is returned if the search fails.


1. Initialize an array of the specified length at random.

2. Sort the array.

3. Enter a value and search for the subscript in the array.


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.