Linear Search Template

Please support our C++ advertiser: Download Intel® Parallel Studio Eval
Reply

Join Date: Nov 2009
Posts: 1
Reputation: kfg20 is an unknown quantity at this point 
Solved Threads: 0
kfg20 kfg20 is offline Offline
Newbie Poster

Linear Search Template

 
0
  #1
Nov 23rd, 2009
I am new to C++ and I need some help getting this code started for this problem. I am asked to do this :
Write a function template version of linearSearch, that can be used to search an array of elements of any type.
Write the function prototype , the function template, and a main function to test it. Test it for an integer array , a double array,and a char array , Also test it when searching for a value that is not in the array.
Any help would be apperciated as this is due in 2 days.

Thank You
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 481
Reputation: Clinton Portis is on a distinguished road 
Solved Threads: 58
Clinton Portis's Avatar
Clinton Portis Clinton Portis is offline Offline
Posting Pro in Training
 
0
  #2
Nov 23rd, 2009
One way I would approach this, is not to worry about templating the function at all until you get a function that does what you want it to do. Once you got that down, you can easily go back and do all the necessary templating.

With that said, just concentrate on writing a basic array sorting function. I would google for c++ bubblesort.

Btw, you have failed to ask an intelligent question in virtually every aspect, so I suggest you don't come back until such time as you show some sort of effort on your part.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1,725
Reputation: firstPerson is a glorious beacon of light firstPerson is a glorious beacon of light firstPerson is a glorious beacon of light firstPerson is a glorious beacon of light firstPerson is a glorious beacon of light firstPerson is a glorious beacon of light 
Solved Threads: 220
firstPerson's Avatar
firstPerson firstPerson is online now Online
Posting Virtuoso
 
0
  #3
Nov 24th, 2009
Do you know how to declare a template function?
The series 1^1 + 2^2 + 3^3 + ... + 10^10 = 10405071317.
Help me find the last ten digits of the series, 1^1 + 3^3 + 5^5 + 7^7 + 9^9 ... 997^997 + 999^999.
Oh come on, someone has to get it! 
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 8,132
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 800
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Code Goddess
 
2
  #4
Nov 24th, 2009
>One way I would approach this, is not to worry about templating the
>function at all until you get a function that does what you want it to do.

Good advice. This is especially useful when writing large template classes due to the "feature" of not instantiating templates that aren't actually used. While some compilers are smart enough to catch it (given the right switches), it's possible to write uncompilable code that doesn't get caught at compile-time:
  1. template <typename T>
  2. class foo {
  3. public:
  4. // Compiles...aroo?
  5. void broken() { asdf }
  6. };
  7.  
  8. int main()
  9. {
  10. foo<int> bar;
  11. }
In case you were wondering, yes, I do hate you.
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the C++ Forum


Views: 421 | Replies: 3
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC