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 Rebote implements Iterator<String> {
- private List<String> lista;
- private int k;
- private int pos= 0;
- private int salto=1;
- public Rebote(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() {
- boolean atras=false;
- pos=pos-1;
- int posantigua=pos;
- if(atras){
- pos--;
- }
- int i;
- for(i=0;i<k;i++){
- pos=pos+salto;
- System.out.println("la pos es " + (pos+1));
- if(pos== lista.size()-1) {
- salto = -1;
- }else {
- salto = 1;
- }
- }
- //pos--;
- String resultado = lista.get(pos);
- return resultado;
- }
- @Override
- public void remove() {
- lista.remove(pos);
- if(pos> lista.size()){
- pos=0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement