class MultiTreeSet< E> {
TreeMap< E, Integer> freqTreeMap = new TreeMap< E, Integer> ( ) ;
int size;
public MultiTreeSet( ) { }
public MultiTreeSet( Collection<? extends E> c) {
for ( E element : c)
add( element) ;
}
public int size( ) {
return size;
}
public void add( E element) {
Integer freq
= freqTreeMap.
get ( element
) ; if ( freq== null )
freqTreeMap.put ( element, 1 ) ;
else
freqTreeMap.put ( element,freq+ 1 ) ;
++ size;
}
public void remove( E element) {
Integer freq
= freqTreeMap.
get ( element
) ; if ( freq!= null ) {
if ( freq== 1 )
freqTreeMap.remove ( element) ;
else
freqTreeMap.put ( element, freq- 1 ) ;
-- size;
}
}
public int get( E element) {
Integer freq
= freqTreeMap.
get ( element
) ; if ( freq== null )
return 0 ;
return freq;
}
public boolean contains( E element) {
return get( element) > 0 ;
}
public boolean isEmpty( ) {
return size== 0 ;
}
public E first( ) {
return freqTreeMap.firstKey ( ) ;
}
public E last( ) {
return freqTreeMap.lastKey ( ) ;
}
public E ceiling( E element) {
return freqTreeMap.ceilingKey ( element) ;
}
public E floor( E element) {
return freqTreeMap.floorKey ( element) ;
}
public E higher( E element) {
return freqTreeMap.higherKey ( element) ;
}
public E lower( E element) {
return freqTreeMap.lowerKey ( element) ;
}
}
Y2xhc3MgTXVsdGlUcmVlU2V0PEU+IHsKCVRyZWVNYXA8RSwgSW50ZWdlcj4gZnJlcVRyZWVNYXAgPSBuZXcgVHJlZU1hcDxFLCBJbnRlZ2VyPigpOwoJaW50IHNpemU7CgkKCXB1YmxpYyBNdWx0aVRyZWVTZXQoKSB7fQoJCglwdWJsaWMgTXVsdGlUcmVlU2V0KENvbGxlY3Rpb248PyBleHRlbmRzIEU+IGMpIHsKCQlmb3IoRSBlbGVtZW50IDogYykKCQkJYWRkKGVsZW1lbnQpOwoJfQoJCglwdWJsaWMgaW50IHNpemUoKSB7CgkJcmV0dXJuIHNpemU7Cgl9CgkKCXB1YmxpYyB2b2lkIGFkZChFIGVsZW1lbnQpIHsKCQlJbnRlZ2V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3IoRSBlbGVtZW50KSB7CgkJcmV0dXJuIGZyZXFUcmVlTWFwLmZsb29yS2V5KGVsZW1lbnQpOwoJfQoJCglwdWJsaWMgRSBoaWdoZXIoRSBlbGVtZW50KSB7CgkJcmV0dXJuIGZyZXFUcmVlTWFwLmhpZ2hlcktleShlbGVtZW50KTsKCX0KCQoJcHVibGljIEUgbG93ZXIoRSBlbGVtZW50KSB7CgkJcmV0dXJuIGZyZXFUcmVlTWFwLmxvd2VyS2V5KGVsZW1lbnQpOwoJfQp9
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