Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Grąžinamas aibės poaibis iki elemento.
- *
- * @param element - Aibės elementas.
- * @return Grąžinamas aibės poaibis iki elemento.
- */
- @Override
- public SetADT<E> headSet(E element) {
- if (element == null) {
- throw new IllegalArgumentException("Element is null in headSet(E element)");
- }
- BstSetKTU<E> headSet = new BstSetKTU<>();
- if (contains(element)) {
- for (Iterator<E> it = iterator(); it.hasNext();) {
- E e = it.next();
- int cmp = (c == null) ? e.compareTo(element) : c.compare(e, element);
- if (cmp <= 0) {
- headSet.add(e);
- }
- }
- }
- return headSet;
- }
- /**
- * Grąžinamas aibės poaibis nuo elemento element1 iki element2.
- *
- * @param element1 - pradinis aibės poaibio elementas.
- * @param element2 - galinis aibės poaibio elementas.
- * @return Grąžinamas aibės poaibis nuo elemento element1 iki element2.
- */
- @Override
- public SetADT<E> subSet(E element1, E element2) {
- if (element1 == null || element2 == null) {
- throw new IllegalArgumentException("Element is null in headSet(E element)");
- }
- BstSetKTU<E> subSet = new BstSetKTU<>();
- if (contains(element1) && contains(element2)) {
- for (Iterator<E> it = iterator(); it.hasNext();) {
- E e = it.next();
- int cmp1 = (c == null) ? e.compareTo(element1) : c.compare(e, element1);
- int cmp2 = (c == null) ? e.compareTo(element2) : c.compare(e, element2);
- if (cmp1 >= 0 && 0 >= cmp2) {
- subSet.add(e);
- }
- }
- }
- return subSet;
- }
- /**
- * Grąžinamas aibės poaibis nuo elemento.
- *
- * @param element - Aibės elementas.
- * @return Grąžinamas aibės poaibis nuo elemento.
- */
- @Override
- public SetADT<E> tailSet(E element) {
- if (element == null) {
- throw new IllegalArgumentException("Element is null in headSet(E element)");
- }
- BstSetKTU<E> tailSet = new BstSetKTU<>();
- if (contains(element)) {
- for (Iterator<E> it = iterator(); it.hasNext();) {
- E e = it.next();
- int cmp = (c == null) ? e.compareTo(element) : c.compare(e, element);
- if (cmp >= 0) {
- tailSet.add(e);
- }
- }
- }
- return tailSet;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement