Created
March 15, 2026 10:53
-
-
Save thinkphp/86252477270541a5f0978e23b36ee788 to your computer and use it in GitHub Desktop.
template.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <algorithm> | |
| using namespace std; | |
| // template<typename T> spune compilatorului T este un tip necunoscut, il deduci din apel | |
| template<typename T> | |
| T maxim(T a,T b) { | |
| return (a > b) ? a : b; | |
| } | |
| template<typename T> | |
| void sorteaza(vector<T>& v) { | |
| sort(v.begin(), v.end()); | |
| } | |
| template<typename T> | |
| void afiseaza(const vector<T> &v, const string& sep = " "){ | |
| for(const auto& x: v) { | |
| cout<<x << sep; | |
| } | |
| cout<<endl; | |
| } | |
| int main(int argc, char const *argv[]) | |
| { | |
| cout<<maxim(3,7)<<endl; | |
| cout<<maxim(3.14,2.71)<<endl; | |
| cout<<maxim(string("Ana"), string("Maria")); | |
| vector<int> note = {8,10,5,7,9}; | |
| sorteaza( note ); | |
| afiseaza( note ); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment