here's an example program in C++ that uses a function template to perform linear search on an array: #include <iostream> using namespace std; template <typename T> int linearSearch(T arr[], int size, T key) { for (int i = 0; i < size; i++) { if (arr[i] == key) { return i; // Return the index where key was found } } return -1; // Key not found in array } int main() { int intArr[] = { 1, 2, 3, 4, 5 }; int intSize = sizeof(intArr) / sizeof(intArr[0]); int intKey = 3; cout << "Index of " << intKey << " in intArr: " << linearSearch(intArr, intSize, intKey) << endl; double doubleArr[] = { 1.2, 2.3, 3.4, 4.5, 5.6 }; int doubleSize = sizeof(doubleArr) / sizeof(doubleArr[0]); double doubleKey = 4.5; ...
This blog is about providing theory as well as simple executable codes of different programming languages such as java, C, C++, and web programming, etc. This blog will be helpful to the IT students to learn about programming.