fork download
  1. class MultiTreeSet<E> {
  2. TreeMap<E, Integer> freqTreeMap = new TreeMap<E, Integer>();
  3. int size;
  4.  
  5. public MultiTreeSet() {}
  6.  
  7. public MultiTreeSet(Collection<? extends E> c) {
  8. for(E element : c)
  9. add(element);
  10. }
  11.  
  12. public int size() {
  13. return size;
  14. }
  15.  
  16. public void add(E element) {
  17. Integer freq = freqTreeMap.get(element);
  18. if(freq==null)
  19. freqTreeMap.put(element, 1);
  20. else
  21. freqTreeMap.put(element,freq+1);
  22. ++size;
  23. }
  24.  
  25. public void remove(E element) {
  26. Integer freq = freqTreeMap.get(element);
  27. if(freq!=null) {
  28. if(freq==1)
  29. freqTreeMap.remove(element);
  30. else
  31. freqTreeMap.put(element, freq-1);
  32. --size;
  33. }
  34. }
  35.  
  36. public int get(E element) {
  37. Integer freq = freqTreeMap.get(element);
  38. if(freq==null)
  39. return 0;
  40. return freq;
  41. }
  42.  
  43. public boolean contains(E element) {
  44. return get(element)>0;
  45. }
  46.  
  47. public boolean isEmpty() {
  48. return size==0;
  49. }
  50.  
  51. public E first() {
  52. return freqTreeMap.firstKey();
  53. }
  54.  
  55. public E last() {
  56. return freqTreeMap.lastKey();
  57. }
  58.  
  59. public E ceiling(E element) {
  60. return freqTreeMap.ceilingKey(element);
  61. }
  62.  
  63. public E floor(E element) {
  64. return freqTreeMap.floorKey(element);
  65. }
  66.  
  67. public E higher(E element) {
  68. return freqTreeMap.higherKey(element);
  69. }
  70.  
  71. public E lower(E element) {
  72. return freqTreeMap.lowerKey(element);
  73. }
  74. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:2: error: cannot find symbol
	TreeMap<E, Integer> freqTreeMap = new TreeMap<E, Integer>();
	^
  symbol:   class TreeMap
  location: class MultiTreeSet<E>
  where E is a type-variable:
    E extends Object declared in class MultiTreeSet
Main.java:7: error: cannot find symbol
	public MultiTreeSet(Collection<? extends E> c) {
	                    ^
  symbol:   class Collection
  location: class MultiTreeSet<E>
  where E is a type-variable:
    E extends Object declared in class MultiTreeSet
Main.java:2: error: cannot find symbol
	TreeMap<E, Integer> freqTreeMap = new TreeMap<E, Integer>();
	                                      ^
  symbol:   class TreeMap
  location: class MultiTreeSet<E>
  where E is a type-variable:
    E extends Object declared in class MultiTreeSet
3 errors
stdout
Standard output is empty