A return string is a string. The read from left to right is exactly the same as the read from right to left.For example, "level" and "aaabbaaa"
For recursive retrieval judgment methods, refer to this article: recursive
1 /// <summary> 2 // judge the background (such as "level" and "aaabbaaa ") 3 /// </Summary> 4 /// <Param name = "str"> </param> 5 /// <returns> </returns> 6 public static bool checkpalindrome (string Str) 7 {8 char [] charcompare = Str. tochararray (); 9 // The stack can be inserted and deleted only at the end of the table (after the stack is advanced) 10 stacks <char> S = new stack <char> (); 11 // The queue can only be inserted at the end of the table, and deleted at the end of the header (queue first-in-first-out) 12 queue <char> q = new queue <char> (); 13 bool justfy = true; 14 // press into the stack and queue respectively 15 f Or (INT I = 0; I <Str. length; I ++) 16 {17 s. push (charcompare [I]); 18 Q. enqueue (charcompare [I]); 19} 20 for (INT I = 0; I <Str. length; I ++) 21 {22 // Pop will return and remove the last character pushed into the stack. dequeue will return and remove the first character 23 if (S. pop ()! = Q. dequeue () 24 {25 justfy = false; 26} 27} 28 return justfy; 29}
Judge the background