Is there any way to find index of an element in a treeset in java?
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
Is there any way to find index of an element in a treeset in java?
Name |
---|
Auto comment: topic has been updated by ninjamayank (previous revision, new revision, compare).
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.
Thanks for the reply but I needed a way to do it in logn time
Sighs. You can't
Just use C.
Marinush
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
Thank you for the advice
Refer to this
Thank you very much. It really helped.
What problem caused you to need such a data structure though, I'm curious?
https://codeforces.net/contest/1679/problem/C