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.

Recommended Answers

All 7 Replies

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.

i'll check the tutorial and see if that helps.

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?


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.


Thanks a whole lot man!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.