根据自己微薄的高自考数据结构知识,做了一个
时间复杂度为O(n) 具体值为字符串的长度除以2的向下取整。|_n/2_|
空间复杂度为O(1)
的字符串翻转类
1.翻转类
class StringReversal
{
public String StrReversal(String oldString)
{
//Convert string to char arry
Char[] oldCharArray = oldString.ToCharArray();
//Reversal from zero
int index = 0;
int cLength = oldCharArray.Length - 1;
while(index<cLength)
{
//use char CTemp to swap
char cTemp = oldCharArray[index];
oldCharArray[index] = oldCharArray[cLength];
oldCharArray[cLength] = cTemp;
index ++;
cLength --;
}
//Convert char array to string only have the constructor method
string newString = new string(oldCharArray);
return newString;
}
}
2.测试类
class App
{
public static void Main()
{
StringReversal myReversal = new StringReversal();
Console.WriteLine("please input the string:");
String oldString = Console.ReadLine();
Console.WriteLine(myReversal.StrReversal(oldString));
}
}
3.我想问大家一下,大家如果看了这篇文章真的会去测试吗?我只是想了解
因为我自己真的是个容易嫌麻烦的人,不够务实,尤其是步骤很多,很麻烦的时候,
又担心自己搞得不好,不会搞。
有的时候下定决心来测试吧,又发现作者也是省略一些他认为很小的细节,导致测试失败
艾!我把这个叫 "牛B度",那你扪心自问是不是跟我有同样的感受,如果我这个东西你会
测试,你就发个评论,好吧,我只是想了解.也让路过的人了解,因为我们就是你的镜子.
浙公网安备 33010602011771号