怎样用递归法使字符串倒序
各位高手:怎样用递归法使字符串倒序?
2008-04-08 22:45
2008-04-08 22:56

2008-04-08 23:21
2008-04-15 11:10
2008-04-15 11:10
2008-04-15 12:09
2008-04-15 15:02
2008-04-15 15:38
2008-04-17 19:17
程序代码:
#include <iostream>
using namespace std;
void reverse(string &s, int a, int b)
{
if(a<b)
{
swap(s[a],s[b]);
reverse(s,a+1,b-1);
}
}
int main()
{
string s;
cin>>s;
cout<<"Before reverse:\n"<<s<<endl;
reverse(s, 0, s.length()-1);
cout<<"After reverse:\n"<<s<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
2008-04-18 00:12