| | |
Linear Search Template
![]() |
•
•
Join Date: Nov 2009
Posts: 1
Reputation:
Solved Threads: 0
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
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
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.
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.
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!
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:
>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:
C++ Syntax (Toggle Plain Text)
template <typename T> class foo { public: // Compiles...aroo? void broken() { asdf } }; int main() { foo<int> bar; }
In case you were wondering, yes, I do hate you.
![]() |
Similar Threads
- Linear and Binary Search not working! :( (Java)
- Linear and Binary search (C++)
- Linear Search - pascal HELP! (Pascal and Delphi)
- Code Snippet: Linear search (C++)
- C++ 6. Search Benchmarks. (C++)
- Linear search (C++)
- vBulletin mod_rewrite for vB 3.0.7 (Existing Scripts)
- Linear Search (Java)
Other Threads in the C++ Forum
- Previous Thread: Reset left side of +=
- Next Thread: C++ Programming
Views: 421 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api array arrays beginner binary borland c++ c/c++ calculator char class classes code compile compiler console constructor conversion convert count data delete desktop dll encryption error file forms fstream function functions game givemetehcodez graph homework http iamthwee ifstream input int java lazy lib link linker list loop looping loops map math matrix memory newbie news number objects output pointer pointers problem program programming project python qt random read recursion recursive reference return search sort sorting spoonfeeding string strings struct student studio system template templates text tree url variable vc++ vector video visual visualstudio win32 window windows winsock wordfrequency wxwidgets






