MovieList Flashcards
MovieList();
MovieList::MovieList(): head(NULL){}
~MovieList();
MovieList::~MovieList(){
Node* currNode = head;
Node* nextNode = NULL;
while(currNode!=NULL){ nextNode = currNode->next; delete currNode; currNode = nextNode; } }
void addFront(Movie*);
void MovieList::addFront(Movie* m){
Node* currNode = new Node();
currNode->data = m;
currNode->next = head;
head = currNode;
}
void addBack(Movie*);
void MovieList::addBack(Movie* m){
Node* currNode = new Node();
Node *last = head;
currNode->data = m;
currNode->next = NULL;
if (head == NULL){ head = currNode; return; } while (last->next != NULL){ last = last->next; } last->next = currNode; return; }
bool get(const string& title, Movie**) const;
bool MovieList::get(const string& title, Movie** m) const{
Node * currNode;
currNode = head;
while (currNode!=NULL){ if (currNode->data->getTitle() == title){ break; } currNode = currNode->next; } if (currNode == NULL){ *m = NULL; return false; } *m = currNode->data; return true; }
bool remove(const string& title, Movie**);
bool MovieList::remove(const string& title, Movie ** m){
Node * currNode;
Node * prevNode;
currNode = head;
prevNode = NULL;
while (currNode!=NULL){ if (currNode->data->getTitle() == title){ break; } prevNode = currNode; currNode = currNode->next; } if (currNode == NULL){ *m = NULL; return false; } if (prevNode == NULL){ head = currNode->next; }else{ prevNode->next = currNode->next; } *m = currNode->data; delete currNode; return true; }
void getFamilyMovies(MovieList& fam) const;
void MovieList::getFamilyMovies(MovieList& fam) const{
Node * currNode;
currNode = head;
while (currNode!=NULL){ if (currNode->data->isfamilyMovie()){ fam.addBack(currNode->data); } currNode = currNode->next; } }
void clear();
void MovieList::clear(){
Node* currNode = head;
Node* nextNode = NULL;
while(currNode!=NULL){ nextNode = currNode->next; delete currNode->data; delete currNode; currNode = nextNode; } head = NULL; }