Switch to full style
For C/C++ coders discussions and solutions
Post a reply

Generic Algorithm

Thu Nov 13, 2008 8:11 pm

Generic Algorithm Code
cpp code
#include <iostream>
using namespace std;

template <class X> X sum(X *data, int size)
{
int i;
X result = 0;

for(i = 0; i <size; i++) result += data[ i ];

return result;
}

int main()
{
int i[] = {1, 2, 3, 4};
double d[] = {1.1, 2.2, 3.3, 4.4};

cout << sum(i, 4) << endl;
cout << sum(d, 4) << endl;

return 0;
}




Post a reply
  Related Posts  to : Generic Algorithm
 generic queue     -  
 Need help with generic listeners     -  
 id3 algorithm     -  
 Rijndael Algorithm     -  
 genetic algorithm example     -  
 Data set for ID3 algorithm     -  
 CPU priority algorithm...     -  
 Dijkstra Algorithm     -  
 hungarian algorithm java     -  
 DDA Line Drawing Algorithm     -  

Topic Tags

C++ Algorithms