Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

pointer-nested-classes.iml
README.md
50 changes: 50 additions & 0 deletions src/Collections.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
public class Collections {
private static Integer[] integers;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove static


public Collections(Integer[] integers){
Collections.integers = integers;

}
public firstToLastIterator directIterator() {
return new firstToLastIterator();
}

private static class firstToLastIterator implements Iterator {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F


private int currentIndex;

@Override
public boolean hasNext() {
return currentIndex < integers.length;
}

@Override
public Object next() {
if (currentIndex % 2 != 0) {
currentIndex++;
return 0;
} else {
return integers[currentIndex++];
}
System.out.println(Integer[] integers);
}
}

class lastToFirstIterator implements Iterator {
private int currentIndex = integers.length - 1;

@Override
public boolean hasNext() {
return currentIndex >= 0;
}

@Override
public Object next() {
int index = currentIndex;
currentIndex -= 2;
return integers[index];
}
}


}
6 changes: 6 additions & 0 deletions src/Iterator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public interface Iterator {
boolean hasNext();

Object next();

}
16 changes: 16 additions & 0 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class Main {
public static void main(String[] args) {
Collections collections = new Collections(new Integer[]{10, 11, 12, 13, 14, 15, 16, 17});

Iterator iterator = new collections.directIterator();
display(iterator);
}


static void display(Iterator iterator) {
while (Iterator.hasNext()) {
System.out.println(iterator.next());
}
}
}