-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate function
More file actions
32 lines (32 loc) · 889 Bytes
/
Copy pathtemplate function
File metadata and controls
32 lines (32 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<iostream>
using namespace std;
template <typename T>
getmax(T a, T b){
return(a>b)?a:b;
}
template <typename T>
void myswap(T &x, T &y){
T temp =x;
x=y;
y=temp;
}
int main(){
int a=10, b=20;
cout<< "Max of "<< a << " and " << b << " is " << getmax(a,b)<<endl;
cout<< "Before swap: a = " << a << ", b = " << b << endl;
myswap(a, b);
cout<< "After swap: a = " << a << ", b = " << b << endl;
cout<< "-----------------" <<endl;
double x= 5.5,y=2.3;
cout<< "Max of "<< x << " and " << y << " is " << getmax(a,b)<<endl;
cout<< "Before swap: x = " << x << ", y = " << y << endl;
myswap(x, y);
cout<< "After swap: x = " << x << ", y = " << y << endl;
cout<< "-----------------" <<endl;
char c1='A',c2='Z';
cout<<"Max of"<<c1<<"and"<<c2<<"is:"<<getmax(c1,c2)<<endl;
cout<<"Before swap: c1="<<c1<<", c2="<<c2<<endl;
myswap(c1,c2);
cout<<"After swap:c1="<<c1<<", c2="<<c2<<endl;
return 0;
}