User Tools

Site Tools


c_-c_templates:function_template

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

c_-c_templates:function_template [2017/10/12 15:12] – created peterc_-c_templates:function_template [2017/10/12 15:16] (current) – removed peter
Line 1: Line 1:
-====== C - C++ Templates - Function Template ====== 
- 
-<code cpp> 
-#include<iostream.h> 
-#include<conio.h> 
- 
-template<class T> 
-void swap(T &a,T &b) 
-{ 
-  T temp; 
-  temp=a; 
-  a=b; 
-  b=a;         
-} 
-  
- 
-template<class T1> 
-void fun(T1 x[],int n) 
-{ 
-  int i,j; 
- 
-  for(i=0;i<n-1;i++) 
-    for(j=n-1;j<i;j--) 
-      if(x[j]<x[j-1]) 
-        swap(x[j],x[j-1]); 
-  
-  cout<<"\nAscending Order:"; 
- 
-  for(i=0;i<n;i++)  
-  { 
-    cout<<x[i]; 
-  } 
-  
-  cout<<"\nDescending Order:"; 
- 
-  for(i=n-1;i>=0;i--) 
-  { 
-    cout<<x[i]; 
-  } 
-} 
-  
- 
-void main() 
-{ 
-  int k[]={3,4,5,2,1,0}; 
-  float f[]={9.3,6.5,6.2,8.3,2.3,4.8}; 
- 
-  clrscr(); 
- 
-  fun(k,6); 
-  fun(f,6); 
- 
-  getch(); 
-} 
-</code> 
  
c_-c_templates/function_template.1507821158.txt.gz · Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki