Question: Project : Implement a circularly linked list In a circular linked list, the tail node points to the head node. Implement MyLinkedList class ( Chapter

Project : Implement a circularly linked list
In a circular linked list, the tail node points to the head node. Implement MyLinkedList class (Chapter-24) using a circular linked list. Identify the methods you need to modify and make appropriate changes. Test your new class using the following program.
public class MyCircularLinkedList {
public static void main(String[] args){
// Create a list
MyList list = new MyLinkedList<>();
// Add elements to the list
list.add("America"); // Add it to the list
System.out.println("(1)"+ list);
list.add(0, "Canada"); // Add it to the beginning of the list
System.out.println("(2)"+ list);
list.add("Russia"); // Add it to the end of the list
System.out.println("(3)"+ list);
list.add("France"); // Add it to the end of the list
System.out.println("(4)"+ list);
list.add(2, "Germany"); // Add it to the list at index 2
System.out.println("(5)"+ list);
list.add(5, "Norway"); // Add it to the list at index 5
System.out.println("(6)"+ list);
// Remove elements from the list
list.remove("Canada"); // Same as list.remove(0) in this case
System.out.println("(7)"+ list);
list.remove(2); // Remove the element at index 2
System.out.println("(8)"+ list);
list.remove(list.size()-1); // Remove the last element
System.out.print("(9)"+ list +"
(10)");
for (String s: list)
System.out.print(s.toUpperCase()+"");
System.out.print("
(11)");
list.forEach(e -> System.out.print(e.toLowerCase()+""));
System.out.print("
(12)");
list.stream().sorted().forEach(e -> System.out.print(e +""));
list.clear();
System.out.println("
(13) The list size is "+ list.size());
}
}
class MyLinkedList implements MyList {
// Your implementation
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!