943,671 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 2362
  • C RSS
Jul 1st, 2008
0

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

Expand Post »
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
red devils is offline Offline
4 posts
since Jul 2008
Jul 1st, 2008
0

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

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,949 posts
since Aug 2005
Jul 1st, 2008
0

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

i'll check the tutorial and see if that helps.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
red devils is offline Offline
4 posts
since Jul 2008
Jul 2nd, 2008
0

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

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.
Reputation Points: 83
Solved Threads: 61
Posting Pro in Training
Luckychap is offline Offline
442 posts
since Aug 2006
Jul 2nd, 2008
0

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

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
red devils is offline Offline
4 posts
since Jul 2008
Jul 2nd, 2008
0

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

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.
Reputation Points: 83
Solved Threads: 61
Posting Pro in Training
Luckychap is offline Offline
442 posts
since Aug 2006
Jul 2nd, 2008
0

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

<deleted>
Last edited by Adak; Jul 2nd, 2008 at 3:58 am.
Reputation Points: 416
Solved Threads: 181
Nearly a Posting Virtuoso
Adak is offline Offline
1,463 posts
since Jun 2008
Jul 3rd, 2008
0

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

Thanks a whole lot man!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
red devils is offline Offline
4 posts
since Jul 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: ISO Uses PDFs Too, Standardizes Format
Next Thread in C Forum Timeline: Unable to delete compiled programs?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC