I have a question regarding LinkedList that I’m using to implement a queue. How to move to the tail all elements that stay before the defined element? Let’s say I need to move to the tail all elements that stay before the 3rd element (see the below example). It means that the numbers 1 and 2 should be moved to the tail in order to get: 3->4->1->2.
Is it possible to do something similar to list1.moveToTheTail(startElem,endElem); where startElem and endElem indicate bounds of elements to be moved to the tail?
import java.util.LinkedList;
public class Test {
public static void main(String[] args) {
LinkedList<Integer> list1 = new LinkedList<Integer>();
list1.addLast(1);
list1.addLast(2);
list1.addLast(3);
list1.addLast(4);
list1.
System.out.println(list1);
}
}
no there is no such function .. it’s a pity because the operation move from front to tail is only a change of the “pointer” to the first element.
But you want a function to move also from the middle of the list … here we go: