Answers for "how to sort using bubble sort in c++"

C++
1

bubble sort c++ template

// template <class t>
// void bubble <t>::sort(int n)
template < typename T > void bubble_sort( T a[], int n )
{
    int i,j;
    //t temp;
    T temp ;
    for(i=0; i<n; i++)
    {
        for(j=i+1; j<n; j++)
        {
            if(a[i]>a[j]) //bubble sort algo
            {
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
        }
    }
}
Posted by: Guest on January-04-2021

Browse Popular Code Answers by Language