Linked lists are a very typical data structure used in ADTS like stacks, or queues. For this question, implement the lis
Posted: Mon Jun 06, 2022 6:22 pm
question, implement the list operation shown below: containsDuplicate. This method will check the contents of a list and check if there are any nodes with duplicate elements within it. If needed, you may assume the input list is non-empty. The list is singly linked, and you have only a reference to it's head (not tail). The LinearNode class may be used but you may not import any packages. Creating additional helper methods is fine but you should provide a one line comment that indicates their purpose.
public class LinearNode ( private LinearNode next; public String element; public LinearNode (String elem) (next null; element public LinearNode getNext() { return next; } elem; ) public void setNext (LinearNode node) ( next - node; } //Given the head of a singly linked list, checks if there are any duplicates elements in //the list. You may assume the input list is non-empty. Returns a boolean. //EXAMPLES: containsDuplicates (["A", "B", "C"1) returns false containsDuplicates (["A", "B", "A")) returns true containsDuplicates (["z", "2", "2"]) returns true where brackets show the contents of the list at a high level (the actual value will be head of that list) and the left most node is the head. //Hint: create a method boolean contains (LinearNode head, String element) that checks if an // element exists in the list. public static boolean contains Duplicates (LinearNode head) { //TODO: implement me!
Linked lists are a very typical data structure used in ADTS like stacks, or queues. For this public class LinearNode ( private LinearNode next; public String element; public LinearNode (String elem) (next null; element public LinearNode getNext() { return next; } elem; ) public void setNext (LinearNode node) ( next - node; } //Given the head of a singly linked list, checks if there are any duplicates elements in //the list. You may assume the input list is non-empty. Returns a boolean. //EXAMPLES: containsDuplicates (["A", "B", "C"1) returns false containsDuplicates (["A", "B", "A")) returns true containsDuplicates (["z", "2", "2"]) returns true where brackets show the contents of the list at a high level (the actual value will be head of that list) and the left most node is the head. //Hint: create a method boolean contains (LinearNode head, String element) that checks if an // element exists in the list. public static boolean contains Duplicates (LinearNode head) { //TODO: implement me!