It is currently Tue Mar 16, 2010 11:10 pm


All times are UTC [ DST ]


Ask on Codemiles community and get answers Free and Fast :

Ask your C-C++ questions ,C-C++ codes,C-C++ tricks ,C-C++ faq ,C-C++ answers .and more

Our guest share with us your code snippets , your programming problems , your open source projects ,read articles and post yours .



Registration to Codemiles.com is FAST and FREE. Join Now!





Post new topic Reply to topic  [ 1 post ] 
  Print view Previous topic | Next topic 
Author Message
 Post subject: Generic Algorithm
PostPosted: Thu Nov 13, 2008 8:11 pm 
Offline
Beginner
User avatar

Joined: Sun May 25, 2008 5:34 pm
Posts: 95
Has thanked: 2 time
Have thanks: 0 time
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;
}




TOP
 Profile Send private message  
 
| More
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 


 Similar topics
 Topic title   Forum   Author   Replies 
 java code for decision tree algorithm  Java  PERRYS  1
 apriori algorithm java code  Java  yuva  1
 need a java code for hungarian algorithm  Java  ips1  0
 Need help with generic listeners  Java  sd3245  3
 Spanning Tree Algorithm  Networks  mileloader  0

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  









Home
General Talks
Finished Projects
Code Library
Games
Tutorials
Programming help
Java
C/C++
C-sharp
Web Development
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
SEO
Google SEO
Others
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2009
mileX v1.0 designed by codemiles team