mirror of
https://github.com/Lendaia/oe-alga-feladatok.git
synced 2026-04-23 12:26:07 +01:00
commit
This commit is contained in:
49
ALGA/03_Tomb.cs
Normal file
49
ALGA/03_Tomb.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ namespace OE.ALGA.Paradigmak
|
|||||||
{
|
{
|
||||||
public interface IVegrehajthato
|
public interface IVegrehajthato
|
||||||
{
|
{
|
||||||
public void Vegrehajtas();
|
void Vegrehajtas();
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IFuggo
|
public interface IFuggo
|
||||||
@@ -35,27 +35,45 @@ namespace OE.ALGA.Paradigmak
|
|||||||
|
|
||||||
public void Felvesz(T t)
|
public void Felvesz(T t)
|
||||||
{
|
{
|
||||||
if (n <= tarolo.Length)
|
if (tarolo.Length == 0)
|
||||||
{
|
|
||||||
tarolo[n] = t;
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
throw new TaroloMegteltKivetel();
|
throw new TaroloMegteltKivetel();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (n < tarolo.Length)
|
||||||
|
{
|
||||||
|
tarolo[n] = t;
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new TaroloMegteltKivetel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerator GetEnumerator()
|
public IEnumerator GetEnumerator()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
foreach (T t in tarolo)
|
||||||
|
{
|
||||||
|
if (t != null)
|
||||||
|
{
|
||||||
|
yield return t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual public void MindentVegrehajt()
|
virtual public void MindentVegrehajt()
|
||||||
{
|
{
|
||||||
foreach (T t in tarolo)
|
foreach (T t in tarolo)
|
||||||
{
|
{
|
||||||
t.Vegrehajtas();
|
if (t != null)
|
||||||
|
{
|
||||||
|
t.Vegrehajtas();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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)
|
public FuggoFeladatTarolo(int l) : base(l)
|
||||||
{
|
{
|
||||||
@@ -77,10 +95,14 @@ namespace OE.ALGA.Paradigmak
|
|||||||
{
|
{
|
||||||
foreach (T t in tarolo)
|
foreach (T t in tarolo)
|
||||||
{
|
{
|
||||||
if (t.FuggosegTeljesul)
|
if (t != null)
|
||||||
{
|
{
|
||||||
t.Vegrehajtas();
|
if (t.FuggosegTeljesul)
|
||||||
|
{
|
||||||
|
t.Vegrehajtas();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,22 +4,37 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace OE.ALGA.Paradigmak
|
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)
|
public FeltetelesFeladatTarolo(int l) : base(l)
|
||||||
{
|
{
|
||||||
|
BejaroFeltetel = Igaz;
|
||||||
}
|
}
|
||||||
public void FeltetelesVegrehajtas(Func<T, bool> feltetel)
|
public void FeltetelesVegrehajtas(Func<T, bool> feltetel)
|
||||||
{
|
{
|
||||||
foreach (T t in tarolo)
|
foreach (T t in tarolo)
|
||||||
{
|
{
|
||||||
if (feltetel(t))
|
if (feltetel(t) && t != null)
|
||||||
{
|
{
|
||||||
t.Vegrehajtas();
|
t.Vegrehajtas();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
IEnumerator<T> IEnumerable<T>.GetEnumerator()
|
||||||
|
{
|
||||||
|
FeltetelesFeladatTaroloBejaro<T> bejaro = new FeltetelesFeladatTaroloBejaro<T>(tarolo, n, BejaroFeltetel);
|
||||||
|
return bejaro;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public class FeltetelesFeladatTaroloBejaro<T> : IEnumerator<T>
|
public class FeltetelesFeladatTaroloBejaro<T> : IEnumerator<T>
|
||||||
{
|
{
|
||||||
@@ -71,4 +86,4 @@ namespace OE.ALGA.Paradigmak
|
|||||||
aktualisindex = -1;
|
aktualisindex = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user