-Hello, I am trying to loop through a linked list so that after all elements are looped through, the first element
-is removed from the list, and then after the new loop occurs again, the second item is removed, this occurs until the second to
-last node and last node remain.

Example print out:

loop 1: A,B,C,D,E
loop 2: B,C,D,E
loop 3: C,D,E
loop 4: D,E
loop 5: E



Here is my code (wanting it to do above increment in tree3Loop method.

public void tree3Loop(){
for(int k=0;k<clusterList3.size();k++)
{
buildTree3();
System.out.println(k);

}

}

public void buildTree3() {
// if no common elements, then new node is set as parent and shifted x_increment to right
// if not parent, then attach to node that shares common element(s)
// ListIterator itr3 = clusterList3.listIterator();

//Loop through all pairwise combinations


// ClusterNode's first element is the root node
for (int i=1; i<clusterList3.size(); i++) { // start from 2nd node
ClusterNode2 cNode3 = clusterList3.get(i); // current node
for (int j=0; j<i && cNode3.isRoot(); j++) {
ClusterNode2 pNode3 = clusterList3.get(j); // prev node already has (x,y) fixed
LinkedList<String> commonCDTs3 = cNode3.getCommonCDTs(pNode3);
if (commonCDTs3.size() != 0) {
cNode3.setParent(pNode3); // cNode is child to pNode
pNode3.addChild(cNode3);
}
}
if (cNode3.isRoot()) { // no common elements with any nodes already in list
rootClusterList3.add(cNode3);
cNode3.setLoc(3, x_marker3, y_marker3);
moveMarkers3(); // shift x marker to next parent
}
}


// Now all root nodes have their location fixed so we run BFS to fix children location
for (int i=0; i<rootClusterList3.size(); i++) {
queue3.add(rootClusterList3.get(i));
BFS3();
}



}