void DLList::RemoveFirst(int value){ DLNode* temp = head; bool found = false; while((temp != NULL) && (!found)) { if (temp->GetContents() == value) { if (temp->GetNext() != NULL) { temp->GetNext()->SetPrevious(temp->GetPrevious()); } if (temp->GetPrevious() != NULL) { temp->GetPrevious()->SetNext(temp->GetNext()); } if (temp == head){ head = temp->GetNext(); } else if (temp == tail) { tail = temp->GetPrevious(); } delete temp; temp = NULL; size--; found = true; } if(temp != NULL) { temp = temp->GetNext(); } } if (!found) { cerr << "Not Found" << endl; } }
bool DLList::Exists(int value){ DLNode* temp = head; while (temp != NULL) { if (temp->GetContents() == value) { return true; } temp = temp->GetNext(); } return false; }
string DLList::ToStringForwards(){ if (head == NULL){ cerr << "List Empty" << endl; return ""; } stringstream ss; DLNode* temp = head; while(temp != NULL) { ss << temp->GetContents(); if (temp != tail){ ss << ", "; } temp = temp->GetNext(); } return ss.str(); }