Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

bubblesort

Void bubbleSort(int arr[ ], int n){
           For( int I = 0;  I < n-1; I++){          //outer loop for iterating to n-1 elements
                    For( int j = 0; j < n-I-1; j++){      //inner loop for checking each element
                         If (arr[ j ] > arr[ j+1 ]{            // For swapping if previous element is greater than next one
                               Swap( arr[ j ], arr[ j+1 ]);
                             }
                     }
             }
}
Source by www.codingninjas.com #
 
PREVIOUS NEXT
Tagged: #bubblesort
ADD COMMENT
Topic
Name
2+2 =