diff --git a/src/aud/exam/prep/list/DoubleListItem.java b/src/aud/exam/prep/list/DoubleListItem.java index 31ae3b7..a404cc4 100644 --- a/src/aud/exam/prep/list/DoubleListItem.java +++ b/src/aud/exam/prep/list/DoubleListItem.java @@ -1,7 +1,17 @@ package aud.exam.prep.list; -public class DoubleListItem { +public class DoubleListItem implements ListItem { public T key; - public DoubleListItem next; public DoubleListItem prev; + public DoubleListItem next; + + @Override + public T head() { + return key; + } + + @Override + public ListItem tail() { + return next; + } } \ No newline at end of file diff --git a/src/aud/exam/prep/list/ListItem.java b/src/aud/exam/prep/list/ListItem.java new file mode 100644 index 0000000..3ed7b02 --- /dev/null +++ b/src/aud/exam/prep/list/ListItem.java @@ -0,0 +1,8 @@ +package aud.exam.prep.list; + +public interface ListItem { + + T head(); + + ListItem tail(); +} diff --git a/src/aud/exam/prep/list/ListItemIterator.java b/src/aud/exam/prep/list/ListItemIterator.java new file mode 100644 index 0000000..1379fd1 --- /dev/null +++ b/src/aud/exam/prep/list/ListItemIterator.java @@ -0,0 +1,24 @@ +package aud.exam.prep.list; + +import java.util.Iterator; + +public class ListItemIterator implements Iterator { + + private ListItem current; + + public ListItemIterator(ListItem current) { + this.current = current; + } + + @Override + public boolean hasNext() { + return current != null; + } + + @Override + public T next() { + T t = current.head(); + current = current.tail(); + return t; + } +} diff --git a/src/aud/exam/prep/list/SingleListItem.java b/src/aud/exam/prep/list/SingleListItem.java index 9e8e028..ef81604 100644 --- a/src/aud/exam/prep/list/SingleListItem.java +++ b/src/aud/exam/prep/list/SingleListItem.java @@ -1,6 +1,17 @@ package aud.exam.prep.list; -public class SingleListItem { +public class SingleListItem implements ListItem { + public T key; public SingleListItem next; + + @Override + public T head() { + return key; + } + + @Override + public ListItem tail() { + return next; + } } \ No newline at end of file