// // CD Organizer // #include using namespace std ; #include "cdorganizer.h" // Constructor // Pre - None // Post - headptr_ListByArtist = null // headptr_ListByYear = null cdorganizer::cdorganizer(void){ headptr_ListByArtist = (singlylinkednode*) NULL ; headptr_ListByYear = (doublylinkednode*) NULL ; } // Desctructor // Pre - None // Post - free memory of headptr_ListByArtist // free memory of headptr_ListByYear cdorganizer::~cdorganizer(void){ // traverse one of the lists and delete all the data // and also traverse both lists and delete all the linked list nodes /* ************************************************** */ /* * YOU WRITE THIS CODE FOR HOMEWORK 2 !!!!!!!! **** */ /* ************************************************** */ } // IsEmpty // Pre - None // Post - returns true if the lists are empty, false if they are not bool cdorganizer::IsEmpty(void) const{ // return true if empty, false is not // remember that since the lists hold the same data, you only need to look at 1 of them /* ************************************************** */ /* * YOU WRITE THIS CODE FOR HOMEWORK 2 !!!!!!!! **** */ /* ************************************************** */ } // Exists // Pre - None // Post - Returns true if the CD already exists in the list (Name & Title are the same) // Returns false if the CD is not found bool cdorganizer::Exists(musiccd findthiscd) const{ // traverse one of the linked list and return true if found, false if not // and remember that since the lists hold the exact same data, you only need to search 1 of them /* ************************************************** */ /* * YOU WRITE THIS CODE FOR HOMEWORK 2 !!!!!!!! **** */ /* ************************************************** */ } // AddCD // Pre - None // Post - Add 'amusiccd' to headptr_ListByArtist // Add 'amusiccd' to headptr_ListByYear // Unless amusiccd already exists, then simply return false bool cdorganizer::AddCD(musiccd amusiccd){ if(this->Exists(amusiccd) == true) { // CD is a duplicate, don't insert it! return false ; } else { // CD does not exists, so insert it! // first create the muscicd cd on the heap so that we are saving it musiccd * newdata = new musiccd(amusiccd) ; // second, create the node for the single linked list singlylinkednode * newbyartistnode = new singlylinkednode() ; newbyartistnode->data = newdata ; // third, create the node for the double linked list doublylinkednode * newbyyearnode = new doublylinkednode() ; newbyyearnode->data = newdata ; // fourth, traverse both linked lists ... and insert the data in the proper location // remember that the singly linked list by Artist ... uses the Album Title to break ties // and remember that the doubly linked list by Year ... uses the Artist Name to break ties /* ************************************************** */ /* * YOU WRITE THIS CODE FOR HOMEWORK 2 !!!!!!!! **** */ /* ************************************************** */ } } // RemoveCD // Pre - None // Post - Find MusicCD and remove from headptr_ListByArtist // Find MusicCD and remove from headptr_ListByYear // Unless not found, then simply return false bool cdorganizer::RemoveCD(musiccd thecd){ // traverse the linked list and find the item to delete // and if you find it, remove it and delete the memory on the heap for the data & node, and return true // and if you don't find it, just return false // remember that there are 2 lists so you will have to delete the data once, and also delete the 2 nodes /* ************************************************** */ /* * YOU WRITE THIS CODE FOR HOMEWORK 2 !!!!!!!! **** */ /* ************************************************** */ } // PrintCDsByArtist // Pre - None // Post - Print Music CDs using overloaded << using headptr_ListByArtist void cdorganizer::PrintCDsByArtist(void) const{ singlylinkednode * current = headptr_ListByArtist ; cout << "-----------------------" << endl ; cout << "CDs By Artist " << endl ; cout << "-----------------------" << endl ; int counter = 1 ; while(current != NULL){ cout << counter << ".)" ; current->data->PrintMusicCD() ; cout << endl ; current = current->next ; counter++ ; } } // PrintCDsByYearASCAndAlbum // Pre - None // Post - Print Music CDs using headptr_ListByYear void cdorganizer::PrintCDsByYearASC(void) const{ doublylinkednode * current = headptr_ListByYear ; cout << "-------------------------------" << endl ; cout << "CDs By Year ASC " << endl ; cout << "-------------------------------" << endl ; int counter = 1 ; do { if(current != NULL) { cout << counter << ".)" ; current->data->PrintMusicCD() ; cout << endl ; current = current->next ; counter++ ; } } while(current != NULL && current != headptr_ListByYear) ; } // PrintCDsByYearDESCAndAlbum // Pre - None // Post - Print Music CDs using using headptr_ListByYear, but go backwards! void cdorganizer::PrintCDsByYearDESC(void) const{ doublylinkednode * current = (doublylinkednode*) NULL ; cout << "--------------------------------" << endl ; cout << "CDs By Year DESC " << endl ; cout << "--------------------------------" << endl ; /* ************************************************** */ /* * YOU WRITE THIS CODE FOR HOMEWORK 2 !!!!!!!! **** */ /* ************************************************** */ }