//reverse()的实现#include #include char* reverse(char* s){ int i,j; for (i=0,j=strlen(s)-1; i
//reverse()函数模板的实现#include #include using namespace std;template void reverse ( BidirectionalIterator first, BidirectionalIterator last){ while ((first!=last)&&(first!=--last)) { *first = *first^*last; *last = *first^*last; *first = *first^*last; ++first; }}template BidirectionalIterator reverse2(BidirectionalIterator first, BidirectionalIterator last){ BidirectionalIterator begin = first; while ((first!=last)&&(first!=--last)) { *first = *first^*last; *last = *first^*last; *first = *first^*last; ++first; } return begin;}int main(){ char str[]="abcdefghijklmnopqrstuvwxyz"; cout << str << endl; reverse(str,str+strlen(str)); cout << str << endl; cout << reverse2(str,str+strlen(str)) << endl; return 0;}