Re: Palindrome
- From: Randy Howard <randyhoward@xxxxxxxxxxxxxxxxx>
- Date: Tue, 17 Oct 2006 23:22:44 GMT
John Smith wrote
(in article <LVMYg.146809$1T2.30093@pd7urf2no>):
tawsword wrote:
Hey Fellas, what's the pseudocode for a program to detect a word ifc
it's a palindrome or not, using linked lists?
Compare first letter with last letter, then 2nd letter with
penultimate letter, and so on. Continue this process until you
reach the middle. Here's a function in C that does it:
/* return a boolean value indicating
whether str is a palindrome */
int ispal(char *str)
{
int lo, hi, mid;
hi = strlen(str) - 1;
mid = hi / 2;
for(lo = 0; lo <= mid; lo++, hi--)
{
if(str[lo] != str[hi])
return 0;
}
return 1;
}
Why do you want to use a linked list?
Because the professor picked the wrong problem to use for a
linked list homework assignment?
--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw
.
- References:
- Palindrome
- From: tawsword
- Re: Palindrome
- From: John Smith
- Palindrome
- Prev by Date: Re: memset problems
- Next by Date: Re: My project
- Previous by thread: Re: Palindrome
- Next by thread: whether an array H[1..n] is aheap
- Index(es):
Relevant Pages
|