This commit is contained in:
Lendaia Mirai
2025-09-24 23:55:52 +02:00
committed by hallgato
parent 1d80c9e3fb
commit 887f659b57
3 changed files with 102 additions and 16 deletions

49
ALGA/03_Tomb.cs Normal file
View File

@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OE.ALGA.Adatszerkezetek
{
public class TombVerem<T> : Verem<T>
{
T[] tomb;
int n = 0;
public TombVerem(int l)
{
tomb = new T[l];
}
public bool Ures => throw new NotImplementedException();
public T Felso()
{
throw new NotImplementedException();
}
public void Verembe(T ertek)
{
if (n < tomb.Length)
{
tomb[n] = ertek;
n++;
}
else
{
throw new NincsHelyKivetel();
}
}
public T Verembol()
{
for (int i = tomb.Length; i > 0; i--)
{
if (tomb[i] != null)
{
return tomb[i];
}
}
throw new NincsElemKivetel();
}
}
}

View File

@@ -6,7 +6,7 @@ namespace OE.ALGA.Paradigmak
{
public interface IVegrehajthato
{
public void Vegrehajtas();
void Vegrehajtas();
}
public interface IFuggo
@@ -35,7 +35,13 @@ namespace OE.ALGA.Paradigmak
public void Felvesz(T t)
{
if (n <= tarolo.Length)
if (tarolo.Length == 0)
{
throw new TaroloMegteltKivetel();
}
else
{
if (n < tarolo.Length)
{
tarolo[n] = t;
n++;
@@ -46,18 +52,30 @@ namespace OE.ALGA.Paradigmak
}
}
}
public IEnumerator GetEnumerator()
{
throw new NotImplementedException();
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()
{
@@ -67,7 +85,7 @@ namespace OE.ALGA.Paradigmak
}
public class FuggoFeladatTarolo<T> : FeladatTarolo<T> where T : IVegrehajthato, IFuggo
public class FuggoFeladatTarolo<T> : FeladatTarolo<T>, IEnumerable<T> where T : IVegrehajthato, IFuggo
{
public FuggoFeladatTarolo(int l) : base(l)
{
@@ -76,12 +94,16 @@ namespace OE.ALGA.Paradigmak
override public void MindentVegrehajt()
{
foreach (T t in tarolo)
{
if (t != null)
{
if (t.FuggosegTeljesul)
{
t.Vegrehajtas();
}
}
}
}
}
public class FeladatTaroloBejaro<T> : IEnumerator<T>

View File

@@ -4,22 +4,37 @@ using System.Collections.Generic;
namespace OE.ALGA.Paradigmak
{
public class FeltetelesFeladatTarolo<T> : FeladatTarolo<T> where T : IVegrehajthato
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 (feltetel(t))
if (feltetel(t) && t != null)
{
t.Vegrehajtas();
}
}
}
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
FeltetelesFeladatTaroloBejaro<T> bejaro = new FeltetelesFeladatTaroloBejaro<T>(tarolo, n, BejaroFeltetel);
return bejaro;
}
}
public class FeltetelesFeladatTaroloBejaro<T> : IEnumerator<T>
{