mirror of
https://github.com/Lendaia/oe-alga-feladatok.git
synced 2026-04-23 04:16:32 +01:00
74 lines
1.7 KiB
C#
74 lines
1.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
namespace OE.ALGA.Paradigmak
|
|
{
|
|
public class FeltetelesFeladatTarolo<T> : FeladatTarolo<T> where T : IVegrehajthato
|
|
{
|
|
public FeltetelesFeladatTarolo(int l) : base(l)
|
|
{
|
|
|
|
}
|
|
public void FeltetelesVegrehajtas(Func<T, bool> feltetel)
|
|
{
|
|
foreach (T t in tarolo)
|
|
{
|
|
if (feltetel(t))
|
|
{
|
|
t.Vegrehajtas();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public class FeltetelesFeladatTaroloBejaro<T> : IEnumerator<T>
|
|
{
|
|
T[] tarolo;
|
|
int n;
|
|
int aktualisindex;
|
|
public Func<T, bool> Feltetel
|
|
{
|
|
get;
|
|
}
|
|
public T Current
|
|
{
|
|
get { return tarolo[aktualisindex]; }
|
|
}
|
|
public FeltetelesFeladatTaroloBejaro(T[] tarolo, int n, Func<T, bool> feltetel)
|
|
{
|
|
this.tarolo = tarolo;
|
|
this.n = n;
|
|
aktualisindex = 0;
|
|
Feltetel = feltetel;
|
|
}
|
|
object IEnumerator.Current => throw new NotImplementedException();
|
|
|
|
public void Dispose()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public bool MoveNext()
|
|
{
|
|
if (aktualisindex < n - 1)
|
|
{
|
|
aktualisindex++;
|
|
if (Feltetel(tarolo[aktualisindex]))
|
|
{
|
|
return true;
|
|
}
|
|
MoveNext();
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
aktualisindex = -1;
|
|
}
|
|
}
|
|
} |