Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package br.uefs.ecomp.treeStock.util;
- import java.util.Iterator;
- /**
- *
- * @author dcandrade
- */
- public class inOrderIterator implements Iterator {
- LinkedList stack;
- public inOrderIterator(Node root) {
- stack = new LinkedList();
- this.inOrder(root);
- }
- public void inOrder(Node root) {
- if (root != null) {
- this.inOrder(root.getLeftChild());
- stack.insereFinal(root.getData());
- this.inOrder(root.getRightChild());
- }
- }
- @Override
- public boolean hasNext() {
- return !this.stack.estaVazia();
- }
- @Override
- public Object next() {
- if (this.hasNext()) {
- try {
- return this.stack.removeInicio();
- } catch (DadoNaoEncontradoException ex) {
- return null;
- }
- } else {
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement