Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of TreeSet in Java to C#.net

I have Java code containing a TreeSet. I want to convert the code to C#.

Which equivalent collection can I use?
If there is none please suggest alternatives.

like image 593
usr021986 Avatar asked Jul 26 '11 09:07

usr021986


People also ask

What is the equivalent of TreeSet in C++?

You can use std::set here.

What is a tree set in Java?

TreeSet is one of the most important implementations of the SortedSet interface in Java that uses a Tree for storage. The ordering of the elements is maintained by a set using their natural ordering whether or not an explicit comparator is provided.

Is TreeSet a binary tree?

The TreeSet uses a self-balancing binary search tree, more specifically a Red-Black tree. Simply put, being a self-balancing binary search tree, each node of the binary tree comprises of an extra bit, which is used to identify the color of the node which is either red or black.

How is TreeSet implemented in Java?

When we implement a TreeSet, it creates a TreeMap to store the elements. It sorts the elements either naturally or using the user define comparator. When the object of a TreeSet is created, it automatically invokes the default constructor and creates an object of TreeMap and assigns comparator as null.

What is the use of treeset in Java?

Java TreeSet class. Java TreeSet class implements the Set interface that uses a tree for storage. It inherits AbstractSet class and implements NavigableSet interface. The objects of TreeSet class are stored in ascending order. The important points about Java TreeSet class are: Contains unique elements only like HashSet.

What is the difference between HashSet and Java treeset?

Java TreeSet class contains unique elements only like HashSet. Java TreeSet class access and retrieval times are quiet fast. Java TreeSet class doesn't allow null element.

What is the difference between treeset and SortedSet in Java?

TreeSet implements the SortedSet interface so duplicate values are not allowed. Objects in a TreeSet are stored in a sorted and ascending order. TreeSet does not preserve the insertion order of elements but elements are sorted by keys. TreeSet does not allow to insert Heterogeneous objects.

Does Java treeset class allow null element?

Java TreeSet class doesn't allow null element. Java TreeSet class is non synchronized. Java TreeSet class maintains ascending order. As shown in the above diagram, Java TreeSet class implements the NavigableSet interface.


2 Answers

That would be System.Collections.Generic.SortedSet<T>.

It does have the methods and complexity guarantees that one would expect from a balanced tree-backed data structure. You can find maximum, minimum, iterate through all elements in order, everything.

See Add to SortedSet<T> and its complexity for more on that.

like image 63
user7610 Avatar answered Oct 06 '22 00:10

user7610


I think there is no treeset in C#.

There was similar question asked in msdn, check that may be useful. http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/823c46ca-4a60-4429-a606-e76c3195d4cc/

like image 44
Loga Avatar answered Oct 05 '22 23:10

Loga