text: Recursive Bubble Sort | C / C ++ program for recursive implementation of Bubble sort ; A function to implement bubble sort ; Base case ; One pass of bubble sort . After this pass , the largest element is moved ( or bubbled ) to end . ; swap arr [ i ] , arr [ i + 1 ] ; Largest element is fixed , recur for remaining array ; Function to print an array ; Driver program to test above functions
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; void bubbleSort ( int arr [ ] , int n ) { if ( n == 1 ) return ; for ( int i = 0 ; i < n - 1 ; i ++ ) if ( arr [ i ] > arr [ i + 1 ] ) swap ( arr [ i ] , arr [ i + 1 ] ) ; bubbleSort ( arr , n - 1 ) ; } void printArray ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) printf ( " % d ▁ " , arr [ i ] ) ; printf ( " STRNEWLINE " ) ; } int main ( ) { int arr [ ] = { 64 , 34 , 25 , 12 , 22 , 11 , 90 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; bubbleSort ( arr , n ) ; printf ( " Sorted ▁ array ▁ : ▁ STRNEWLINE " ) ; printArray ( arr , n ) ; return 0 ; }