簡體   English   中英

遍歷樹集中的元素並更新 Java 中的排序

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

我有三組三組,我想在算法上做到這一點:

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
  }
}

這樣做的最佳方法是什么? 一個非常簡單的例子:

treeset1
treeset2
treeset3
treeset4

去treeset1,在上面做點什么,如果做完了,然后去掉treeset1,排序,下一個元素會變成treeset4(原來是treeset2),現在在treeset4上做點,沒做,不去掉treeset4,再排序,下一個是treeset3 ,做某事,完成,treeset3 完成,再次排序,treeset4 再次出現在排序中,在treeset4 上做某事.....

最佳做法是什么? 我有有效的排序功能。 一旦我到達最后一個元素並且無法刪除更多元素,算法就會停止。

我想出來用迭代器來做。 每次循環后,我都會使用迭代器並調用 next()。 它解決了我的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM