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.

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:

struct node {
        char data;
        node *next;
        node *prev;
};

Then write some functions to add, delete and traverse etc And what write functions for what u exactly want.

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?

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:

//Assuming that head and tail are global
int isPalindrome() {
       node *tempHead = head;
       node *tempTail = tail;
     
       //function to calculate the length of link list
       int length = getLength();
       int i = 0;
       for(;i<length/2;i++) {
             if(tempHead->data != tempTail->data)
                  return 0;
       
             tempHead = tempHead->next;
             tempTail = tempTail->prev;
      }
      return 1;
}

Hope u got it.

This question has already been answered. Start a new discussion instead.