Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // cw program rozdzial 8 ad.6
- #include <iostream>
- template <typename T>
- void max(T var1[], int tSize);
- template <> void max <char*> (char * arr[], int tSize);
- int main()
- {
- using namespace std;
- int arr1[5] = { 1,2,3,4,5 };
- cout << sizeof(arr1) / sizeof(arr1[0]) << endl;
- max(arr1, 5);
- double arr2[4] = { 1.1, 1.2, 1.3, 1.4 };
- cout << endl << sizeof(arr2) / sizeof(arr2[0]) << endl;
- max(arr2, 5);
- char * arr3[4] = { "trzybobry", "czterybobry", "piecbobrow", "szescbobrow" };
- cout << endl << &arr3[3];
- cout << endl << arr3[3];
- cout << endl;
- max(arr3, 4);
- return 0;
- }
- template <typename T>
- void max(T var1[], int tSize)
- {
- T max = var1[0];
- for (int i = 1; i < tSize; i++)
- {
- if (var1[i] > max) max = var1[i];
- }
- std::cout << max;
- }
- template <> void max <char*>(char * arr[], int tSize)
- {
- int * length = new int[tSize];
- for (int i = 0; i < tSize; i++)
- {
- length[i] = 0;
- for (char j = *arr[0]; j != '\0'; j++) length[i] ++;
- }
- int max = length[0];
- char * adress = arr[0];
- for (int i = 1; i < tSize; i++)
- {
- if (length[i] > max)
- {
- max = length[i];
- adress = arr[i];
- }
- }
- std::cout << adress;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement