Linked List

I have been working on a project using linked list for the past week am I close to finishing but I am trying to tie up some lose ends. We had to create a linked list based of a long file of movies. I am able to build the list but the way the project works is the user inputs a string and I have to take that string to find a title in the linked list of movies that matches. This is how I attemp to do it:

const Movie * Movies::movieSearch(string mc) const {
string target = mc;
while ((movies2->getTitle() != target) && (movies2->getNextLink() != NULL)) {
movies2->getNextLink();
}

if (movies2->getTitle() == target)
return &movies2->getData();
else
return NULL;
}

There are no compile errors but when I try to test it in main, it does nothing:

m = movies.movieSearch(movieCode);

My main problem is trying to figure out how I can access the title after asking for the data. The following two methods are in my node.h file:

string getTitle() const {return title;}
T getData() {return data;}

Please let me know if you have any idea how I can fix this problem. Not sure if I'm suppose to declare a new node in the movieSearch or not. Thanks!
i think here is your problem:

1
2
3
while ((movies2->getTitle() != target) && (movies2->getNextLink() != NULL)) {
movies2->getNextLink();
}


you call getNextLink twice.
I think that you do not move across your linked list, that is the following code

1
2
3
while ((movies2->getTitle() != target) && (movies2->getNextLink() != NULL)) {
movies2->getNextLink();
}


seems does not move to the next link.

So please show your method getNextLink.
Topic archived. No new replies allowed.