MtK Posted May 10, 2005 Posted May 10, 2005 Hi,I need to use the TreeMap included with the JDK to store some sortable data.In addition to maintaining the TreeMap, I need to create a Linked-List, while adding elements to the TreeMap.At the end of the Insertion/Deletion, it should look like this:(no need to be circular)any Ideas?
MtK Posted May 29, 2005 Author Posted May 29, 2005 //this code time complexity: O(log(n))//MyEntry is the type of the objects within the tree nodes.//key is of type Object//m_treemap is an instance of TreeMapSortedMap tailMap = m_treemap.tailMap(key);MyEntry succ = null;MyEntry pred = null;if (!tailMap.isEmpty()) { succ = (MyEntry) m_treemap.get(tailMap.firstKey()); pred = succ.m_pred;} else { //no successor - the pred is the last key in the tree if (!m_treemap.isEmpty()) { pred = (MyEntry) m_treemap.get(m_treemap.lastKey()); }}//now succ and pred contains the real successor and predecessor of key
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now