Write a template version of Bubble sort algorithm. The function should look like:
template <class T>
void BubbleSort(T A[], int N)
where A -- array to sort, N -- number of elements in the array
#include <iostream>
using namespace std;
template <class T>
void BubbleSort(T A[], int N){
int i, j, buf;
int N=1000;
for (i=0; i<N-1; i++)
for (j=i+1;j<N;j++)
if (A[i]>arr[j])
{
buf = A[i];
A[i] = A[j];
A[j] = buf;
}
}
if you are accepting N as a parameter why do you reinitialize it?
N should be the number of items in the area which would already be coming from main()
#include <iostream>
using namespace std;
template <class T>
void BubbleSort(T A[], int N){
int i, j, buf;
for (i=0; i<N-1; i++)
{
for (j=i+1;j<N;j++)
{
if (A[i]>arr[j])
{
buf = A[i];
A[i] = A[j];
A[j] = buf;
}
}
}
}