// ************************************ //
// protected search agent //
// ************************************ //
CHAR_DL_CELL* CHAR_DLLIST::get_element_address(CHAR search_key)
{
CHAR_DL_CELL *temp;
if(!(head==NULL)){
temp = head;
if(search_key==temp->element) return(temp);
temp = head->next;
while(!(temp==NULL)){
if(search_key==temp->element) return(temp);
temp = temp->next;
}
}
cout << "The element " << search_key << " is not in the list."
<< endl;
return(NULL);
}
// ************************************ //
// find address before a given element //
// ************************************ //
CHAR_DL_CELL* CHAR_DLLIST::get_before_element_address(CHAR search_key)
{
CHAR_DL_CELL *temp;
if(!(head==NULL)){
temp = head;
if(search_key==temp->element){
cout << "search_key is at head of list, so before address is NULL"
<< endl;
return(NULL);
}
while(!(temp->next==NULL)){
if(search_key==temp->next->element){
//temp is address of cell before cell containing search_key
return(temp);
}
temp = temp->next;
}
}
cout << "The element " << search_key << " is not in the list."
<< endl;
return(NULL);
}
// ************************************ //
// find address after a given element //
// ************************************ //
CHAR_DL_CELL* CHAR_DLLIST::get_after_element_address(CHAR search_key)
{
CHAR_DL_CELL *temp;
if(!(head==NULL)){
temp = head;
if(search_key==temp->element){
cout << "search_key is at head of list, so after address is head->next."
<< endl;
return(temp->next);
}
temp = temp->next;
while(!(temp==NULL)){
if(search_key==temp->element){
//temp->next is address of cell after cell containing search_key
return(temp->next);
}
temp = temp->next;
}
}
cout << "The element " << search_key << " is not in the list."
<< endl;
return(NULL);
}