Skip to content
Snippets Groups Projects
Commit 40e52b8e authored by NGUYEN Thi hang's avatar NGUYEN Thi hang
Browse files

THN

parent 2640a150
No related branches found
No related tags found
No related merge requests found
......@@ -33,6 +33,6 @@ public class ArrayGrid implements Grid{
}
}
public Iterator<Cell> iterator(){
return new CellGridIterator();
return new CellGridIterator(this);
}
}
......@@ -2,29 +2,25 @@ package model;
public class CellGridIterator implements Iterator<Cell>{
ArrayGrid grid;
Iterator<Cell> it=grid.iterator();
int indixRow;
int indixColum;
public CellGridIterator(ArrayGrid grid) {
this.grid = grid;
this.indixColum=0;
this.indixRow=0;
}
public SquareCell next() {
int i = 0;
while (i < grid.getNumberOfRows()) {
while (it.hasNext()) {
return it.next();
}
i++;
public Cell next() {
final Cell result = grid.getCell(indixRow, indixColum);
indixColum = (indixColum +1) % grid.getNumberOfColumns();
if(indixColum == 0){
indixRow++;
}
}
public boolean hasNext( ){
int n;
if(n>= grid.getNumberOfColumns()|| n>= grid.getNumberOfRows()) return false;
return result;
}
public boolean hasNext(){
return this.indixColum < this.grid.getNumberOfColumns() && indixRow < this.grid.getNumberOfRows();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment