Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package e2;
- import java.util.Iterator;
- import java.util.List;
- public class Circular implements Iterator<String>{
- private List<String> lista;
- public void setK(int k) {
- this.k = k;
- }
- public int getK() {
- return k;
- }
- private int k;
- private int pos= 0;
- private int poscorrecta;
- public Circular(List<String> lista, int k){
- this.lista=lista;
- this.k=k;
- }
- @Override
- public boolean hasNext() {
- if (lista.size()>1){
- return true;
- } else return false;
- }
- @Override
- public String next() {
- pos=pos+k-1;
- poscorrecta = pos % lista.size();
- String resultado = lista.get(poscorrecta);
- return resultado;
- }
- @Override
- public void remove() {
- lista.remove(poscorrecta);
- if(pos> lista.size()){
- pos=0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement