Basic Application Skills of C ++ Bubble Sorting

Source: Internet
Author: User

For those who have learned C language, they may be very impressed with the Bubble sorting. Today, we will introduce the implementation of Bubble Sorting in C ++ with C language features. Next, let's take a look at the specific operation methods of C ++ Bubble sorting.

C ++ Bubble Sorting code example:

 
 
  1. # Include <iostream. h>
  2. # Include <stdio. h>
  3. /*
  4. Bubble Sorting
  5. Paramter:
  6. Int * pData: pointer Array
  7. Int Count: array size
  8. Return value: returns the pointer to the array.
  9. */
  10. Int * BubbleSort (int * pData, int Count)
  11. {
  12. Int iTemp;
  13. For (int I = 1; I <Count; I ++)
  14. {
  15. For (int j = Count-1; j> = I; j --)
  16. {
  17. If (pData [j] <pData [J-1])
  18. {
  19. ITemp = pData [J-1];
  20. PData [J-1] = pData [j];
  21. PData [j] = iTemp;
  22. }
  23. }
  24. }
  25. Return pData;
  26. }
  27. Void main ()
  28. {
  29. Int a [10] = };
  30. Int count = sizeof (a)/sizeof (a [0]);
  31. Int * B = BubbleSort (a, count); // defines the pointer
  32. For (int I = 0; I <count; I ++)
  33. {
  34. Cout <* (B + I) <endl;
  35. }
  36. }

The preceding section describes C ++ Bubble 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.