From 887f659b5763501bfcee78d39f568560e19cf7e1 Mon Sep 17 00:00:00 2001 From: Lendaia Mirai Date: Wed, 24 Sep 2025 23:55:52 +0200 Subject: [PATCH] commit --- ALGA/03_Tomb.cs | 49 +++++++++++++++++++++ ALGA/Paradigmak/01_ImperativParadigma.cs | 46 ++++++++++++++----- ALGA/Paradigmak/02_FunkcionalisParadigma.cs | 23 ++++++++-- 3 files changed, 102 insertions(+), 16 deletions(-) create mode 100644 ALGA/03_Tomb.cs diff --git a/ALGA/03_Tomb.cs b/ALGA/03_Tomb.cs new file mode 100644 index 0000000..299739d --- /dev/null +++ b/ALGA/03_Tomb.cs @@ -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 : Verem + { + 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(); + } + } +} diff --git a/ALGA/Paradigmak/01_ImperativParadigma.cs b/ALGA/Paradigmak/01_ImperativParadigma.cs index a9a87fd..3028074 100644 --- a/ALGA/Paradigmak/01_ImperativParadigma.cs +++ b/ALGA/Paradigmak/01_ImperativParadigma.cs @@ -6,7 +6,7 @@ namespace OE.ALGA.Paradigmak { public interface IVegrehajthato { - public void Vegrehajtas(); + void Vegrehajtas(); } public interface IFuggo @@ -35,27 +35,45 @@ namespace OE.ALGA.Paradigmak public void Felvesz(T t) { - if (n <= tarolo.Length) - { - tarolo[n] = t; - n++; - } - else + if (tarolo.Length == 0) { throw new TaroloMegteltKivetel(); } + else + { + if (n < tarolo.Length) + { + tarolo[n] = t; + n++; + } + else + { + throw new TaroloMegteltKivetel(); + } + } + } 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) { - t.Vegrehajtas(); + if (t != null) + { + t.Vegrehajtas(); + } } } @@ -67,7 +85,7 @@ namespace OE.ALGA.Paradigmak } - public class FuggoFeladatTarolo : FeladatTarolo where T : IVegrehajthato, IFuggo + public class FuggoFeladatTarolo : FeladatTarolo, IEnumerable where T : IVegrehajthato, IFuggo { public FuggoFeladatTarolo(int l) : base(l) { @@ -77,10 +95,14 @@ namespace OE.ALGA.Paradigmak { foreach (T t in tarolo) { - if (t.FuggosegTeljesul) + if (t != null) { - t.Vegrehajtas(); + if (t.FuggosegTeljesul) + { + t.Vegrehajtas(); + } } + } } } diff --git a/ALGA/Paradigmak/02_FunkcionalisParadigma.cs b/ALGA/Paradigmak/02_FunkcionalisParadigma.cs index 2a74d77..55e48cf 100644 --- a/ALGA/Paradigmak/02_FunkcionalisParadigma.cs +++ b/ALGA/Paradigmak/02_FunkcionalisParadigma.cs @@ -4,22 +4,37 @@ using System.Collections.Generic; namespace OE.ALGA.Paradigmak { - public class FeltetelesFeladatTarolo : FeladatTarolo where T : IVegrehajthato + public class FeltetelesFeladatTarolo : FeladatTarolo, IEnumerable where T : IVegrehajthato { + public Func BejaroFeltetel + { + get; + set; + } + public bool Igaz(T t) + { + return true; + } + public FeltetelesFeladatTarolo(int l) : base(l) { - + BejaroFeltetel = Igaz; } public void FeltetelesVegrehajtas(Func feltetel) { foreach (T t in tarolo) { - if (feltetel(t)) + if (feltetel(t) && t != null) { t.Vegrehajtas(); } } } + IEnumerator IEnumerable.GetEnumerator() + { + FeltetelesFeladatTaroloBejaro bejaro = new FeltetelesFeladatTaroloBejaro(tarolo, n, BejaroFeltetel); + return bejaro; + } } public class FeltetelesFeladatTaroloBejaro : IEnumerator { @@ -71,4 +86,4 @@ namespace OE.ALGA.Paradigmak aktualisindex = -1; } } -} \ No newline at end of file +}