For Q4: I think this is the optimal code
int recurPalin(char *start, char *end)
{
if (end < start)
return true;
if (*start != *end)
return false;
return recurPalin(start+1, end-1);
}
-
Azhar.
On Tue, Jul 5, 2011 at 12:21 PM, vikas <[email protected]> wrote:
> My program for Q4.
> // recursively find if a given string is palindrome
> bool IsPalindrome(string s, int start, int start2, bool flag)
> {
> bool flag1 = flag;
> if (start >= 0 && start2 < (s.Length))
> {
> char c1 = s[start];
> char c2 = s[start2];
> if (c1.Equals(c2))
> {
> if (start == 0 && start2 == s.Length - 1) { flag =
> true; }
> if (IsPalindrome(s, start - 1, start2 + 1, flag))
> {
> flag1 = true;
> }
> }
> }
> return flag1;
> }
>
> while calling
> if (s.Length % 2 != 0)
> {
> p.IsPalindrome(s, s.Length / 2 - 1, s.Length / 2 + 1,
> false);
> }
> else
> {
> p.IsPalindrome(s, s.Length / 2 - 1, s.Length / 2, false);
>
> }
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/I6SVTB0o-uUJ.
>
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.