I don't really know Java but there were some things I came up with that might be wrong, but what I think is really the problem might be that you are removing nodes from a list that may have more than one children. Why not simply go through the list of Blocks showing the data and then at the end try to remove them?
The only other way I came up with was a bit messy: instead of going from (0) to the end removing nodes as you go down, start from the end to (0) and remove nodes as you go up:
Ex: This means that "ListIterator it = ListHandler.Blocks.listIterator(last_node);"
Algorithm:
Code:
1. initialize array hit_nodes with length of ListHandler.Blocks //let's say 7
2. initialize variable len_nodes to length of array hit_nodes or ListHandler.Blocks
3. loop through ListHandler.Blocks reading data from it and moving to hit_nodes
4. remove node when finished with it
Pseudo-code:
Code:
for int len_nodes=(ListHandler.Blocks.length)
{
loop until len_nodes==0;
{
hit_nodes[len_nodes] = ListHandler.Blocks.listIterator(len_nodes); //move data
ListHandler.Blocks.remove(len_nodes); //now remove node
len_nodes--; //to reflect new length
}
}
Lastly, go back through from beginning of array showing the data as you go down.
Bookmarks