I’m trying to create binary tree that contains two int values and one string value sorted in the lexicographic, but I’m not sure what to do. I’ve created an array list, which has been already sorted, but the binary tree has to be a reference-based which is not sorted and I’m thinking about sorting the list while creating it. Can any one help with this? Any brief idea would be appreciated.
Share
You first should create a class to store your data and implement
Comparableor use aComparator.Then use a
Collectionthat implementsSortedSetto store your data, TreeSet is a good choice. The objects in theSortedSetare stored by reference so if you modify a value set in a local variable it will be modified in the collection as well.Edit: If I understood your question about reference based lists correctly the following is possible in Java.