help needed with C program using a linked list to determine if a word is a palindrome

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jul 2008
Posts: 4
Reputation: red devils is an unknown quantity at this point 
Solved Threads: 0
red devils red devils is offline Offline
Newbie Poster

help needed with C program using a linked list to determine if a word is a palindrome

 
0
  #1
Jul 1st, 2008
Hi,

i'm new to C programming and i could use some help with an assignment. i would like to store a word in a linked list, with each letter of the word in a separate node of the linked list. i would then like to traverse the linked list to check whether the word is a palindrome. the nodes in the palindrome should be double pointer nodes.

i'm not quite sure how to start here, any assistance will be appreciated.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,653
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1500
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: help needed with C program using a linked list to determine if a word is a palindrome

 
0
  #2
Jul 1st, 2008
First you have to declare a structure that is each node. If you search for "linked lists" you will get lots of examples, such as this tutorial by Stanford University.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 4
Reputation: red devils is an unknown quantity at this point 
Solved Threads: 0
red devils red devils is offline Offline
Newbie Poster

Re: help needed with C program using a linked list to determine if a word is a palindrome

 
0
  #3
Jul 1st, 2008
i'll check the tutorial and see if that helps.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 319
Reputation: Luckychap is on a distinguished road 
Solved Threads: 42
Luckychap's Avatar
Luckychap Luckychap is offline Offline
Posting Whiz

Re: help needed with C program using a linked list to determine if a word is a palindrome

 
0
  #4
Jul 2nd, 2008
First create a doubly link list. A doubly link list with each nodes having the address of next and previous node. The structure of the such node is as follows:

  1. struct node {
  2. char data;
  3. node *next;
  4. node *prev;
  5. };

Then write some functions to add, delete and traverse etc And what write functions for what u exactly want.
When you think you have done a lot, then be ready for YOUR downfall.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 4
Reputation: red devils is an unknown quantity at this point 
Solved Threads: 0
red devils red devils is offline Offline
Newbie Poster

Re: help needed with C program using a linked list to determine if a word is a palindrome

 
0
  #5
Jul 2nd, 2008
thanks. each node is supposed to store one character of the entered word. the first and last letters of the word would then be compared and if the same, then the second would be compared to the second to last etc. what would be the best way to do this?
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 319
Reputation: Luckychap is on a distinguished road 
Solved Threads: 42
Luckychap's Avatar
Luckychap Luckychap is offline Offline
Posting Whiz

Re: help needed with C program using a linked list to determine if a word is a palindrome

 
0
  #6
Jul 2nd, 2008
Ok!!

One thing more, you have to maintain two pointers..head and tail. Which will have the addresses of first and last node respectively.

And write a function which will count the length of the link list (ie number of characters).

Once that is done you can loop through the list in this way:

  1. //Assuming that head and tail are global
  2. int isPalindrome() {
  3. node *tempHead = head;
  4. node *tempTail = tail;
  5.  
  6. //function to calculate the length of link list
  7. int length = getLength();
  8. int i = 0;
  9. for(;i<length/2;i++) {
  10. if(tempHead->data != tempTail->data)
  11. return 0;
  12.  
  13. tempHead = tempHead->next;
  14. tempTail = tempTail->prev;
  15. }
  16. return 1;
  17. }

Hope u got it.
When you think you have done a lot, then be ready for YOUR downfall.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 79
Reputation: Adak is an unknown quantity at this point 
Solved Threads: 7
Adak Adak is offline Offline
Junior Poster in Training

Re: help needed with C program using a linked list to determine if a word is a palind

 
0
  #7
Jul 2nd, 2008
<deleted>
Last edited by Adak; Jul 2nd, 2008 at 3:58 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 4
Reputation: red devils is an unknown quantity at this point 
Solved Threads: 0
red devils red devils is offline Offline
Newbie Poster

Re: help needed with C program using a linked list to determine if a word is a palindrome

 
0
  #8
Jul 3rd, 2008
Thanks a whole lot man!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 1511 | Replies: 7
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC