Skip to content
Advertisement

Tag: treeset

Collection cannot be converted to Object[]

Need help with a problem for a class! So I have created an array of names that gets passed to a method named runA in the class Proj04Runner. I need to create a TreeSet of these names to put them in naturally ascending order with no repeating values. However when I run my code, I get an error telling me

Counting Inversions using TreeSet Java

I’m using TreeSet for solving counting inversions problem. I’m using following approach which uses gnu_pbds which works in O(logn) time. Algorithm Insert the first element of the array in the Ordered_Set. For all the remaining element in arr[] do the following: Insert the current element in the Ordered_Set. Find the number of element strictly less than current element + 1

TreeSet constructor with Comparator parameter

In Java’s documentation for its class TreeSet one of the constructors is shown to have the following header: Can someone help explain why there is a constructor for TreeSet which takes a comparator object as its argument? I have no clue why this is done. Answer The elements in a TreeSet are kept sorted. If you use a constructor that

Advertisement