ninjamayank's blog

By ninjamayank, history, 3 years ago, In English

Is there any way to find index of an element in a treeset in java?

  • Vote: I like it
  • -4
  • Vote: I do not like it

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by ninjamayank (previous revision, new revision, compare).

»
3 years ago, # |
  Vote: I like it -7 Vote: I do not like it

why not? iterate over all elements, maintain a counter. when you meet your desired element you return the value of the counter. The time complexity is linear in size of the treeset. but I'm guessing this is not what you're looking for.

Everything is possible — Barrack Schwarzenegger, 2025.

»
3 years ago, # |
  Vote: I like it -27 Vote: I do not like it

Just use C.

Marinush

»
3 years ago, # |
  Vote: I like it +7 Vote: I do not like it

with Treeset, there isn't besides doing linear, however you could implement our own binary tree and use binary search to localize the element. Another option would be use FendWick Tree

»
3 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Refer to this

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

What problem caused you to need such a data structure though, I'm curious?