Question
Add a method rotate() to CircularLinkedList class that shift the list one node, below is the output before and after calling the method. Node 1:
- Add a method rotate() to CircularLinkedList class that shift the list one node, below is the output before and after calling the method.
Node 1: 5
Node 2: 4
Node 3: 3
Node 4: 2
Node 5: 1
Node 1: 4
Node 2: 3
Node 3: 2
Node 4: 1
Node 5: 5
------------------------------------------
public class SinglLinkedList
public E getTail() { return tail.getElement(); } public int getSize() { return size; }
boolean isEmpty() { if (size == 0) { return true; } else { return false; } } void Display() { if(isEmpty()) { System.out.println("Empty List.. "); return; } System.out.println(" Display List: "); Node
public void addAtPos(E e, int position) { //check if the position is correct (from 1 to size) if (position < 1 || position > size) { System.out.println("Invalid Position"); return; } //Check if the position 1 (first node) if (position == 1) { addFirst(e); return; } //any other location Node
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started