| | |
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:
Solved Threads: 0
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.
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.
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.
•
•
Join Date: Jul 2008
Posts: 4
Reputation:
Solved Threads: 0
Re: help needed with C program using a linked list to determine if a word is a palindrome
0
#3 Jul 1st, 2008
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:
Then write some functions to add, delete and traverse etc And what write functions for what u exactly want.
c Syntax (Toggle Plain Text)
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.
When you think you have done a lot, then be ready for YOUR downfall.
•
•
Join Date: Jul 2008
Posts: 4
Reputation:
Solved Threads: 0
Re: help needed with C program using a linked list to determine if a word is a palindrome
0
#5 Jul 2nd, 2008
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:
Hope u got it.
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:
c Syntax (Toggle Plain Text)
//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.
When you think you have done a lot, then be ready for YOUR downfall.
•
•
Join Date: Jun 2008
Posts: 79
Reputation:
Solved Threads: 7
Re: help needed with C program using a linked list to determine if a word is a palind
0
#7 Jul 2nd, 2008
•
•
Join Date: Jul 2008
Posts: 4
Reputation:
Solved Threads: 0
Re: help needed with C program using a linked list to determine if a word is a palindrome
0
#8 Jul 3rd, 2008
![]() |
Other Threads in the C Forum
- Previous Thread: ISO Uses PDFs Too, Standardizes Format
- Next Thread: Unable to delete compiled programs?
Views: 1511 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays asterisks binarysearch calculate changingto char character cm command copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic execv feet fgets file fork forloop framework function functions givemetehcodez grade graphics gtkwinlinux hacking histogram homework include incrementoperators input intmain() iso kernel keyboard km lazy license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft mqqueue mysql number oddnumber odf opensource overwrite owf pdf performance pointer pointers posix problem probleminc process program programming radix recursion recv recvblocked research reversing scanf scripting segmentationfault sequential socket spoonfeeding standard string student systemcall testing threads turboc unix user variable wab whythiscodecausesegmentationfault windowsapi






