How can we insert some nodes into a binary search tree using the TreeMap
that implements a Red-Black tree class. Then use the entrySet
method to get back a Set
version of the TreeMap
through which we can Iterate over, and get ALL of the data.
Asked
Active
Viewed 5,419 times
-1

GOTO 0
- 42,323
- 22
- 125
- 158

user3023320
- 11
- 1
- 4
-
Is this Java or what? – GOTO 0 Dec 02 '13 at 22:56
-
This has nothing to do with binary search. – Martin May 27 '14 at 08:27
1 Answers
1
You could do something like this:
Map<String, String> map = new TreeMap<String, String>(); // create TreeMap
map.put("Key1", "Value1"); // insert a node
map.put("Key2", "Value2"); // insert another node
for (Entry<String, String> entry : map.entrySet()) { // iterate over entrySet
String key = entry.getKey();
String value = entry.getValue();
System.out.println(key + ": " + value);
}
Yours is a very basic question, so I suggest you give a look at the TreeMap documentation for more information.

GOTO 0
- 42,323
- 22
- 125
- 158