-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinkedOrderedList.java
executable file
·113 lines (96 loc) · 2.44 KB
/
LinkedOrderedList.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package com.example.list;
import com.example.binaryTree.LinkedBinarySearchTree;
import com.example.exceptions.*;
import com.example.interfaces.OrderedListADT;
import java.util.Iterator;
/**
* @author Micael
*/
public class LinkedOrderedList<T extends Comparable<? super T>> extends LinkedBinarySearchTree<T> implements OrderedListADT<T> {
public LinkedOrderedList() {
}
/**
* {@inheritDoc }
*/
@Override
public void add(T element) {
if (element == null) {
throw new NullPointerException("The element to be added must not be null");
}
super.addElement(element);
}
/**
* {@inheritDoc }
*/
@Override
public T removeFirst() throws EmptyCollectionException {
return super.removeMin();
}
/**
* {@inheritDoc }
*/
@Override
public T removeLast() throws EmptyCollectionException {
return super.removeMax();
}
/**
* {@inheritDoc }
*/
@Override
public T remove(T element) throws EmptyCollectionException, ElementNotFoundException {
return super.removeElement(element);
}
/**
* {@inheritDoc }
*/
@Override
public T first() throws EmptyCollectionException {
return super.findMin();
}
/**
* {@inheritDoc }
*/
@Override
public T last() throws EmptyCollectionException {
return super.findMax();
}
/**
* {@inheritDoc }
*/
@Override
public boolean isEmpty() {
return super.isEmpty();
}
/**
* {@inheritDoc }
*/
@Override
public int size() {
return super.size();
}
/**
* {@inheritDoc }
*/
@Override
public Iterator<T> iterator() {
return new Iterator<T>() {
final Iterator<T> iteratorInOrder = iteratorInOrder();
@Override
public boolean hasNext() {
return this.iteratorInOrder.hasNext();
}
@Override
public T next() {
return this.iteratorInOrder.next();
}
@Override
public void remove() {
/**
* Não está implementado pois se usar o que já existe ele apenas
* remove a copia, é melhor não colocar a não remover
*/
Iterator.super.remove(); //To change body of generated methods, choose Tools | Templates.
}
};
}
}