I found (here)a sort of implementation of an Iterator in c# that mimics Java's Iterator methods but I'm not quite sure how to use it in my case or if there's an easier option to rewrite this method c#'s way. Original java method:
public RWIterator<T> search (T e){
RWIterator<T> it =null;
RWIterator<T> current = iterator();
RWIterator<T> prev = iterator();
boolean found=false;
while(! found && current.hasNext()){
T el=current.next();
if (el.equals(e)) found = true;
else prev.next();
}
if (found) {
//Iterator<T> tmp = prev;
//System.out.println("searched value is="+tmp.next());
it = prev;
}
return it;
}
Where RWIterator extends java Iterator, I can't understand the use of prev .I'm stuck at this point:
public RWIterator<T> Search(T e)
{
RWIterator<T> it = null;
RWIterator<T> current = Iterator();
RWIterator<T> prev = Iterator();
bool found = false;
while (!found && current.GetEnumerator().MoveNext())
{
T el = current.GetEnumerator().Current;
if (el.Equals(e)) found = true;
else
{
//what should happen with prev.GetEnumerator().Current ?
}
}
if (found)
{
//Iterator<T> tmp = prev;
//System.out.println("searched value is="+tmp.next());
it = prev;
}
return it;
}