Files
ALGA/ALGA/Paradigmak/02_FunkcionalisParadigma.cs
Lendaia Mirai 1d80c9e3fb Work
2025-09-24 22:47:27 +02:00

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;
}
}
}