//Catalog.cpp //Brooke Loftus #include Catalog::Catalog() { title = "untitled"; } Catalog::Catalog(const Catalog&cat) { this=cat; } void Catalog::setTitle(string &_title) { title=_title; } void Catalog::showTitleAndSize() { cerr << "For File '" << title << "' of size: " << size() << endl; } void Catalog::operator += (const CatalogEntry &e) { CatalogNode *newNode = new CatalogNode (e); if ( head==NULL) //empty list so far { head = newNode; return; }//if if (e < head.entry) //need to insert in front of 'head' { newNode->next = head; head->previous = newNode; head = newNode; return; }//if //find the right node AFTER which to insert CatalogNode *spot=head; while( (spot->next != NULL)&&(spot->next.entry < e) ) spot = spot->next; //need to insert after spot, which may be pointing to the last node, but that works too newNode->next=spot->next; spot->next = newNode; newNode->previous = spot; if( newNode->next !=NULL ) //if not at end newNode->next->previous = newNode; return; }//operator =+ friend istream &operator >>(istream &in, Catalog &cat) { CatalogEntry entry; while (in.peek () != EOF) { in >> entry; cat += entry; } return in; } friend ostream &operator <<(ostream &out, const Catalog &cat) { for(CatalogNode current=cat.head; current!=NULL; current=current->next) out << current.entry.callNumber << ' ' << current.entry.author << ": " << current.entry.title << endl; return out; } void Catalog::makeEmpty() { head = NULL; }//makeEmpty bool Catalog::isEmpty() const { if ( head == NULL ) return true; else return false; }//isEmpty int Catalog::size() const { int size=0; CatalogNode current = head; while (current != NULL) { current = head->next; size++; } return size; }//size Catalog Catalog::returnEleven(int spot, Catalog &search) { CatalogNode current=head; for(int i=0; inext; } Catalog newCat=current; for(i=0; i<11; i++) { current=current->next; newCat+=current; } return newCat; }//returnEleven void Catalog::sort() { /*Catalog newCat; CatalogNode current; string currentCall; currentEntry = head.entry; for(int i=0; i<*this.getSize(); i++) for(current = head; current != NULL; current= current->next) { if(currentEntry.callNumber == current.entry.callNumber) if(currentEntry.author == current.entry.author) if( currentEntry.title < current.entry.title ) currentEntry }//for */ *this=newCat; }//sort Catalog Catalog::searchTitle(string _title) const { Catalog newCat; for( CatalogNode current=head; current!=NULL; current=current->next) { if( current.entry.title == _title ) newCat+=current.entry; }//for return newCat; }//searchTitle Catalog Catalog::searchAuthor(string author) const { Catalog newCat; for( CatalogNode current=head; current!=NULL; current=current->next;) { if( current.entry.author == author ) newCat+=current.entry; }//for return newCat; }//searchAuthor