mirror of
https://github.com/Lendaia/oe-alga-feladatok.git
synced 2026-04-23 12:26:07 +01:00
Work
This commit is contained in:
@@ -4,6 +4,126 @@ using System.Collections.Generic;
|
||||
|
||||
namespace OE.ALGA.Paradigmak
|
||||
{
|
||||
// 1. heti labor feladat - Tesztek: 01_ImperativParadigmaTesztek.cs
|
||||
}
|
||||
public interface IVegrehajthato
|
||||
{
|
||||
public void Vegrehajtas();
|
||||
}
|
||||
|
||||
public interface IFuggo
|
||||
{
|
||||
public bool FuggosegTeljesul
|
||||
{
|
||||
get;
|
||||
}
|
||||
}
|
||||
|
||||
public class TaroloMegteltKivetel : Exception
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class FeladatTarolo<T> : IEnumerable<T> where T : IVegrehajthato
|
||||
{
|
||||
internal T[] tarolo;
|
||||
internal int n;
|
||||
|
||||
public FeladatTarolo(int l)
|
||||
{
|
||||
tarolo = new T[l];
|
||||
n = 0;
|
||||
}
|
||||
|
||||
public void Felvesz(T t)
|
||||
{
|
||||
if (n <= tarolo.Length)
|
||||
{
|
||||
tarolo[n] = t;
|
||||
n++;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new TaroloMegteltKivetel();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator GetEnumerator()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
virtual public void MindentVegrehajt()
|
||||
{
|
||||
foreach (T t in tarolo)
|
||||
{
|
||||
t.Vegrehajtas();
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator<T> IEnumerable<T>.GetEnumerator()
|
||||
{
|
||||
FeladatTaroloBejaro<T> bejaro = new FeladatTaroloBejaro<T>(tarolo, n);
|
||||
return bejaro;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class FuggoFeladatTarolo<T> : FeladatTarolo<T> where T : IVegrehajthato, IFuggo
|
||||
{
|
||||
public FuggoFeladatTarolo(int l) : base(l)
|
||||
{
|
||||
|
||||
}
|
||||
override public void MindentVegrehajt()
|
||||
{
|
||||
foreach (T t in tarolo)
|
||||
{
|
||||
if (t.FuggosegTeljesul)
|
||||
{
|
||||
t.Vegrehajtas();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public class FeladatTaroloBejaro<T> : IEnumerator<T>
|
||||
{
|
||||
T[] tarolo;
|
||||
int n;
|
||||
int aktualisindex;
|
||||
|
||||
public FeladatTaroloBejaro(T[] tarolo, int n)
|
||||
{
|
||||
this.tarolo = tarolo;
|
||||
this.n = n;
|
||||
aktualisindex = 0;
|
||||
}
|
||||
public T Current
|
||||
{
|
||||
get { return tarolo[aktualisindex]; }
|
||||
}
|
||||
|
||||
object IEnumerator.Current => throw new NotImplementedException();
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (aktualisindex < n-1)
|
||||
{
|
||||
aktualisindex++;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
aktualisindex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,5 +4,71 @@ using System.Collections.Generic;
|
||||
|
||||
namespace OE.ALGA.Paradigmak
|
||||
{
|
||||
// 2. heti labor feladat - Tesztek: 02_FunkcionálisParadigmaTesztek.cs
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user