Andrew
By: a guest | Feb 9th, 2010 | Syntax:
C++ | Size: 1.53 KB | Hits: 12 | Expires: Never
void Clib::add(Sbook &value)
{
List *newl = new List;
newl->value = value;
newl->next = NULL;
if (pFirst == NULL)
pFirst = newl;
else{
List *tmp;
for (tmp=pFirst; tmp->next != NULL; tmp=tmp->next);
tmp->next = newl;
}
//List *newl = new List;
//newl->value = value;
//newl->next = newl->prev = NULL;
//if (pend){
// if (pend == pFirst){
// pend = newl;
// pFirst->next = pend;
// pend->prev = pFirst;
// }
// else{
// newl->prev = pend;
// pend->next = newl;
// pend = newl;
// }
//}
//else
// pFirst = pend = newl;
}
bool Clib::remove_book(Sbook &book)
{
List *pkey = search_book(book);
List *tmp;
if (pkey){
for (tmp=pFirst; tmp->next != NULL; tmp=tmp->next);
if (pkey == pFirst){
if (pFirst->next != NULL)
pFirst = pFirst->next;
else
pFirst = NULL;
}
else{
for (tmp=pFirst; tmp->next != pkey; tmp=tmp->next);
if (pkey == tmp->next)
tmp->next = pkey->next;
else
tmp->next = NULL;
}
delete pkey;
return true;
}
return false;
//List *pkey = search_book(book);
//if (pkey){
// if (pkey == pFirst){
// if (pFirst == pend){
// pend = pFirst = NULL;
// }
// else{
// pFirst = pFirst->next;
// pFirst->next = pkey->next->next;
// }
// }
// else
// if (pkey == pend){
// pend = pend->prev;
// pend->next = NULL;
// }
// else{
// pkey->prev->next = pkey->next;
// pkey->next->prev = pkey->prev;
// }
// delete pkey;
// return true;
//}
//return false;
}