Roman
BAN USER
Comments (5)
Reputation 230
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
That should do the trick:
public static Object stepInIterator(List list, int i){
Stack<Iterator> stack = new Stack<>();
stack.push(list.iterator());
while (!stack.isEmpty()){
while (stack.peek().hasNext()){
Object o = stack.peek().next();
if(o instanceof Iterable){
stack.push(((Iterable)o).iterator());
} else {
if(i-- == 0)
return o;
}
}
stack.pop();
}
return null;
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
- Roman August 16, 2016