Answer to Question #228014 in C++ for Harris

Question #228014
Write a bool function which deletes an element in the linked list
-bool delete_element(int a)
Another function which checks if the list is empty
-bool isempty()
1
Expert's answer
2021-08-22T00:26:44-0400
bool delete_element(int a) {
    LinkedList* prev = head; 
    LinkedList* current = head_pNextValue; 
    while(current != NULL) {
        if(current_value == a) { 
            break; 
        }
        else {
            cout << "Value " << current_value << " does not match " << a << ".\n";
            prev = current; 
            current = current_pNextValue; 
        }
    }
    if(current == NULL) { 
        cout << "Can't remove value: no match found.\n"; 
    } else {
        cout << "Deleting: " << current << "\n";
        prev->pNextValue = current_pNextValue; 
        delete current; 
    }
}
list<int> myList;
bool isempty(){
    if (myList.empty())
      cout << "my list is empty\n";
   else
      cout << "my list isn’t empty\n";
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS