Skip to content
Advertisement

Removing all instances of an element from a custom LinkedList

Im trying to remove all people from the list who have the same course name in my custom LinkedList class. I have managed to get my programme to delete people individually based on number however can not figure out how to remove multiple at once. I have browsed online for any solutions and have tried multiple so far but none to any success I also attempted one myself but also no success any help or links to were I could learn mode would be greatly appreciated. Below is my Driver, LinkedList, and LinearNode class. I have also removed code I beleive is not relevant to this solution :).

Linked List Class

JavaScript

LinearNode Class

JavaScript

Driver Class

JavaScript

Advertisement

Answer

I don’t understand exactly what you want, because of you wrote you want “to remove all people from the list who have the same course name”, but your code never checks only property, your code checks equality everywhere.

This example clear function removes all elements equals to param and returns count of removed elements.

JavaScript

And after all .equals(..) only true, if the compared Objects has an equals() method and checks its content equality, otherwise two Objects equals by == operator, if they are exactly the same (not by there’s contents).

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement