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:
- # Include <iostream. h>
- # Include <stdio. h>
- /*
- Bubble Sorting
- Paramter:
- Int * pData: pointer Array
- Int Count: array size
- Return value: returns the pointer to the array.
- */
- Int * BubbleSort (int * pData, int Count)
- {
- Int iTemp;
- For (int I = 1; I <Count; I ++)
- {
- For (int j = Count-1; j> = I; j --)
- {
- If (pData [j] <pData [J-1])
- {
- ITemp = pData [J-1];
- PData [J-1] = pData [j];
- PData [j] = iTemp;
- }
- }
- }
- Return pData;
- }
- Void main ()
- {
- Int a [10] = };
- Int count = sizeof (a)/sizeof (a [0]);
- Int * B = BubbleSort (a, count); // defines the pointer
- For (int I = 0; I <count; I ++)
- {
- Cout <* (B + I) <endl;
- }
- }
The preceding section describes C ++ Bubble sorting.