Judge the background

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.