Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Introduce en la cola el parametro pNum.
- * @param pNum es el numero que se introduce en la cola.
- * @return devuelve true si se ha podido introducir correctamente
- * @throws IllegalStateException si el numero a introducir no corresponde en signo
- * al anterior, salta esta excepcion.
- */
- public boolean add(int pNum) throws Exception {
- if (!isEmpty()) {
- if ((lista.get(lista.size() - 1) < 0 && pNum > 0) || (lista.get(lista.size() - 1) > 0 && pNum < 0)) {
- lista.add(pNum);
- return true;
- } else if (lista.get(lista.size() - 1) == pNum) {
- return true;
- } else {
- throw new IllegalStateException();
- }
- } else {
- lista.add(pNum);
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement