c_-c_templates:function_template
Differences
This shows you the differences between two versions of the page.
c_-c_templates:function_template [2017/10/12 15:12] – created peter | c_-c_templates:function_template [2017/10/12 15:16] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== C - C++ Templates - Function Template ====== | ||
- | |||
- | <code cpp> | ||
- | # | ||
- | # | ||
- | |||
- | template< | ||
- | void swap(T &a,T &b) | ||
- | { | ||
- | T temp; | ||
- | temp=a; | ||
- | a=b; | ||
- | b=a; | ||
- | } | ||
- | |||
- | |||
- | template< | ||
- | void fun(T1 x[],int n) | ||
- | { | ||
- | int i,j; | ||
- | |||
- | for(i=0; | ||
- | for(j=n-1; | ||
- | if(x[j]< | ||
- | swap(x[j], | ||
- | |||
- | cout<<" | ||
- | |||
- | for(i=0; | ||
- | { | ||
- | cout<< | ||
- | } | ||
- | |||
- | cout<<" | ||
- | |||
- | for(i=n-1; | ||
- | { | ||
- | cout<< | ||
- | } | ||
- | } | ||
- | |||
- | |||
- | void main() | ||
- | { | ||
- | int k[]={3, | ||
- | float f[]={9.3, | ||
- | |||
- | clrscr(); | ||
- | |||
- | fun(k,6); | ||
- | fun(f,6); | ||
- | |||
- | getch(); | ||
- | } | ||
- | </ | ||
c_-c_templates/function_template.1507821158.txt.gz · Last modified: 2020/07/15 09:30 (external edit)