mirror of
https://github.com/Lendaia/oe-alga-feladatok.git
synced 2026-04-23 12:26:07 +01:00
152 lines
3.1 KiB
C#
152 lines
3.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
namespace OE.ALGA.Paradigmak
|
|
{
|
|
public interface IVegrehajthato
|
|
{
|
|
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 (tarolo.Length == 0)
|
|
{
|
|
throw new TaroloMegteltKivetel();
|
|
}
|
|
else
|
|
{
|
|
if (n < tarolo.Length)
|
|
{
|
|
tarolo[n] = t;
|
|
n++;
|
|
}
|
|
else
|
|
{
|
|
throw new TaroloMegteltKivetel();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public IEnumerator GetEnumerator()
|
|
{
|
|
foreach (T t in tarolo)
|
|
{
|
|
if (t != null)
|
|
{
|
|
yield return t;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
virtual public void MindentVegrehajt()
|
|
{
|
|
foreach (T t in tarolo)
|
|
{
|
|
if (t != null)
|
|
{
|
|
t.Vegrehajtas();
|
|
}
|
|
}
|
|
}
|
|
|
|
IEnumerator<T> IEnumerable<T>.GetEnumerator()
|
|
{
|
|
FeladatTaroloBejaro<T> bejaro = new FeladatTaroloBejaro<T>(tarolo, n);
|
|
return bejaro;
|
|
}
|
|
|
|
}
|
|
|
|
public class FuggoFeladatTarolo<T> : FeladatTarolo<T>, IEnumerable<T> where T : IVegrehajthato, IFuggo
|
|
{
|
|
public FuggoFeladatTarolo(int l) : base(l)
|
|
{
|
|
|
|
}
|
|
override public void MindentVegrehajt()
|
|
{
|
|
foreach (T t in tarolo)
|
|
{
|
|
if (t != null)
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
}
|