C recursively implements palindromic judgment algorithm

  • 2020-11-18 06:26:23
  • OfStack

This article describes the example of C# recursive palindrome judgment algorithm, Shared for your reference. Specific implementation methods are as follows:

static void Main(string[] args)
{
    DateTime dt1 = DateTime.Now;     string text = "abcdedcba";
    bool bYes = Recv(text);
    Console.Write("{0} : {1} Palindrome! ", text, bYes ? " is " : " not ");     DateTime dt2 = DateTime.Now;
    Console.Write(" Time: {0} ms ", (dt2 - dt1).TotalMilliseconds.ToString());
    Console.ReadLine();
} private static bool Recv(string text)
{
    string head = text.Substring(0, 1);
    string end = text.Substring(text.Length - 1, 1);
    if (head == end)
    {
 if (text.Length == 1)
     return true;
 string t = text.Substring(1, text.Length - 2);
 return Recv(t);
    }
    return false;
}

Hopefully this article has helped you with your C# programming.


Related articles: