Bubble sort using genric function

// Bubble.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

template <class X>
void bubble( X *agr_sort , int count)
{
register int a , b;
X temp;
for(a= 0; a<count ; a++)
{
for(b=count -1; b>a ; b--)
{
if(agr_sort[b-1] > agr_sort[b])
{
temp = agr_sort[b-1];
agr_sort[b-1] = agr_sort[b];
agr_sort[b] = temp;
}
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int a[7] = {7 , 5 , 4 , 3 ,9 , 8 , 6 };
float b[10] = { 55 , 44 , 66 , 88 , 84 , 33 , 41 , 64 , 21 , 40 };
bubble( a, 7);
bubble( b , 10);
return 0;
}

Comments

Popular posts from this blog

Smart Pointers in C++ and How to Use Them

Operator Overloading in C++

How would you read in a string of unknown length without risking buffer overflow