泛型随机迭代器

    技术2024-11-12  25

    #include<iostream> using namespace std; template<typename PTR, typename DATA> void reverse1(PTR start , PTR beyond) { PTR Start = start; PTR Beyond = beyond; while(Start != Beyond) { --Beyond; if(Start != Beyond) { DATA temp = *Start; *Start = *Beyond; *Beyond = temp; ++Start; } } } int main() { int a[] = {1,2,3,4,5}; reverse1<int *,int>(a,a+5); for(int i=0; i<5; i++) cout<<a[i]<<endl; }

    最新回复(0)