Given the above linked list write the 2 methods below (removeDuplicates and showLL)
C.
package Final;
import java.util.HashSet;
public class LLCycle_FE {
public static void main(String[] args) {
Node head = buildLL();
// Given the above linked list write the 2 methods below (removeDuplicates and showLL)
System.out.printf("\n --------- ");
// This method will remove any duplicate LL nodes (that is, with the same color)
head = removeDuplicates( head );
showLL( head );
}
**public static Node removeDuplicates(Node head) {
return head;
}
** private static void showLL(Node head) {
// ToDo: Output the entire linked list
}
private static Node buildLL() {
// Use this code to create your LL
Node head = new Node("Red", null);
Node n2 = new Node("Blue", null);
head.next = n2;
Node n3 = new Node("Green", null);
n2.next = n3;
Node n4 = new Node("Yellow", null);
n3.next = n4;
Node n5 = new Node("Blue", null );
n4.next = n5;
Node n6 = new Node("Yellow", null );
n5.next = n6;
return head;
}
public static class Node {
// Used this Node for a LL node
public String color;
public Node next;
public Node(String color, Node next) {
this.color = color;
this.next = next;
}
}
}
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)