mirror of
https://github.com/Lendaia/oe-alga-feladatok.git
synced 2026-04-23 12:26:07 +01:00
92 lines
2.2 KiB
C#
92 lines
2.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
namespace OE.ALGA.Paradigmak
|
|
{
|
|
public class FeltetelesFeladatTarolo<T> : FeladatTarolo<T>, IEnumerable<T> where T : IVegrehajthato
|
|
{
|
|
public Func<T, bool> BejaroFeltetel
|
|
{
|
|
get;
|
|
set;
|
|
}
|
|
public bool Igaz(T t)
|
|
{
|
|
return true;
|
|
}
|
|
public FeltetelesFeladatTarolo(int l) : base(l)
|
|
{
|
|
BejaroFeltetel = Igaz;
|
|
}
|
|
public void FeltetelesVegrehajtas(Func<T, bool> feltetel)
|
|
{
|
|
foreach (T t in tarolo)
|
|
{
|
|
if (t != null && feltetel(t))
|
|
{
|
|
t.Vegrehajtas();
|
|
}
|
|
}
|
|
}
|
|
IEnumerator<T> IEnumerable<T>.GetEnumerator()
|
|
{
|
|
FeltetelesFeladatTaroloBejaro<T> bejaro = new FeltetelesFeladatTaroloBejaro<T>(tarolo, n, BejaroFeltetel);
|
|
return bejaro;
|
|
}
|
|
|
|
}
|
|
public class FeltetelesFeladatTaroloBejaro<T> : IEnumerator<T> where T : IVegrehajthato
|
|
{
|
|
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;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
aktualisindex = -1;
|
|
}
|
|
}
|
|
}
|