Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstring>
- using namespace std;
- const int LINE_BUFFER_SIZE = 256;
- struct CharLinkD {
- CharLinkD *prev;
- char c;
- CharLinkD *next;
- };
- // detects if a word is a palindrome
- void makeList(const char candidate[], CharLinkD* &head, CharLinkD* &tail) {
- // get the length of the c-string
- int len = strlen(candidate);
- CharLinkD* first = NULL;
- CharLinkD* temp = NULL;
- //make first link
- first = new CharLinkD;
- first->prev = NULL;
- first->next = NULL;
- first->c = candidate[0];
- //make head and tail point to it
- head = first;
- tail = first;
- //make the list
- for(int i = 1; i < len; i++)
- {
- //make a new link for each character left
- temp = new CharLinkD;
- //make a link that goes back to tail
- temp->prev = tail;
- //link forward is null
- temp->next=NULL;
- temp->c = candidate[i];
- //set up link backward to end of list
- tail->next = temp;
- //new tail is now last element
- tail = temp;
- }
- }
- bool isPalindrome(CharLinkD * head, CharLinkD * tail) {
- bool answer = true;
- //YOUR CODE HERE
- return answer;
- }
- // reads in the list of words
- // prints out word if it is a palendrome
- int main() {
- CharLinkD *head = NULL;
- CharLinkD *tail = NULL;
- // open a file for READING
- ifstream infile("words");
- // create a buffer to hold a line of text from the file
- char line[LINE_BUFFER_SIZE];
- // while not at the end of file
- while (!infile.eof()) {
- // get a line of the file into the buffer
- infile.getline(line, LINE_BUFFER_SIZE);
- makeList(line, head, tail);
- // use our function to check if it's a palindrome
- if (isPalindrome(head, tail)) {
- cout << line << endl;
- }
- }
- infile.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement