Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

bubble sort c++

#include <bits/stdc++.h>
using namespace std;
int main (void) {
    int a[] = {5, 4, 3, 2, 1}, tempArr, i, j;
    for (i = 0; i < 5; i++) {
        for (j = i + 1; j < 5; j++) {
            if (a[j] < a[i]) {
                tempArr = a[i];
                a[i] = a[j];
                a[j] = tempArr;
            }
        }
    }
    for(i = 0; i < 5; i++) {
        cout<<a[i]<<"
";  
    }  
    return 0; 
}
Source by www.softwaretestinghelp.com #
 
PREVIOUS NEXT
Tagged: #bubble #sort
ADD COMMENT
Topic
Name
7+4 =