简体   繁体   English

遍历树集中的元素并更新 Java 中的排序

[英]Going through elements in treeset and update the sorting in Java

I have three set of three sets and I want to do this algorithmically:我有三组三组,我想在算法上做到这一点:

For the first treeset in treesets do till all done:
  dosomething(treeset)
  if done(treeset) {
   remove treeset from treesets
   sort treesets
  // now the next treeset to dosomething will be the first treeset in treesets   since we change the sorting but I want to make sure the sorting is applied there
  }
}

What is the best way of doing that?这样做的最佳方法是什么? A very simple example:一个非常简单的例子:

treeset1
treeset2
treeset3
treeset4

Go to treeset1, do something on it, if done, then remove treeset1, sort, next element will become treeset4 (originally was treeset2), now do something on treeset4, not done, do not remove treesert4, sort again, the next is treeset3, do something, done, treeset3 done, sort again, again treeset4 comes up in sortting, do something on treeset4 .....去treeset1,在上面做点什么,如果做完了,然后去掉treeset1,排序,下一个元素会变成treeset4(原来是treeset2),现在在treeset4上做点,没做,不去掉treeset4,再排序,下一个是treeset3 ,做某事,完成,treeset3 完成,再次排序,treeset4 再次出现在排序中,在treeset4 上做某事.....

What is the best practice?最佳做法是什么? I have the sorting function that works.我有有效的排序功能。 The algorithm will stop once I reach the last element and could not remove any more element.一旦我到达最后一个元素并且无法删除更多元素,算法就会停止。

I figured it out to do it with Iterator.我想出来用迭代器来做。 After each loop, I resort the iterator and call for next().每次循环后,我都会使用迭代器并调用 next()。 It solved my problem.它解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM