From 3d5a324e8c94cbfcb0b67d01a8bf8351265ee354 Mon Sep 17 00:00:00 2001 From: Lendaia Mirai Date: Sat, 4 Oct 2025 19:43:17 +0200 Subject: [PATCH] lol --- ALGA/03_Tomb.cs | 234 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 230 insertions(+), 4 deletions(-) diff --git a/ALGA/03_Tomb.cs b/ALGA/03_Tomb.cs index 299739d..05b7f48 100644 --- a/ALGA/03_Tomb.cs +++ b/ALGA/03_Tomb.cs @@ -1,5 +1,8 @@ -using System; +using OE.ALGA.Paradigmak; +using System; +using System.Collections; using System.Collections.Generic; +using System.Collections.Immutable; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -10,11 +13,15 @@ namespace OE.ALGA.Adatszerkezetek { T[] tomb; int n = 0; + bool ures = true; public TombVerem(int l) { tomb = new T[l]; } - public bool Ures => throw new NotImplementedException(); + public bool Ures + { + get { return ures; } + } public T Felso() { @@ -27,6 +34,7 @@ namespace OE.ALGA.Adatszerkezetek { tomb[n] = ertek; n++; + ures = false; } else { @@ -40,10 +48,228 @@ namespace OE.ALGA.Adatszerkezetek { if (tomb[i] != null) { - return tomb[i]; + return tomb[i];//should i actually delete it, or we are just courious whats the valueidk } } + ures = true; throw new NincsElemKivetel(); } } -} + public class TombSor : Sor + { + T[] tomb; + int n = 0; + bool ures = true; + public TombSor(int l) + { + tomb = new T[l]; + } + + public bool Ures + { + get { return ures; } + } + + public T Elso() + { + return tomb[0]; + } + + public void Sorba(T ertek) + { + if (n < tomb.Length) + { + tomb[n] = ertek; + n++; + ures = false; + } + else + { + throw new NincsHelyKivetel(); + } + } + + public T Sorbol() + { + for (int i = tomb.Length; i > 0; i--) + { + if (tomb[i] != null) + { + return tomb[i];//should i actually delete it, or we are just courious whats the valueidk + } + } + ures = true; + throw new NincsElemKivetel(); + } + } + public class TombLista : Lista, IEnumerable + { + T[] tomb; + int n = 0; + public TombLista(int l) + { + tomb = new T[l]; + } + + public int Elemszam + { + get { return n; } + } + + public void Bejar(Action muvelet) + { + throw new NotImplementedException(); + } + + public void Beszur(int index, T ertek) + { + if (index < 0) + { + throw new HibasIndexKivetel(); + } + if (index < tomb.Length && tomb[index] == null) + { + tomb[index] = ertek; + } + else + { + T[] tmp = new T[tomb.Length * 2]; + for (int i = 0; i < index; i++) + { + tmp[i] = tomb[i]; + } + tmp[index] = ertek; + for (int i = index+1; i < tomb.Length; i++) + { + tmp[i] = tomb[i]; + } + tomb = tmp; + } + n++; + } + + public IEnumerator GetEnumerator() + { + foreach (T t in tomb) + { + if (t != null) + { + yield return t; + } + } + } + + public void Hozzafuz(T ertek) + { + if (n < tomb.Length) + { + tomb[n] = ertek; + } + else + { + T[] tmp = new T[tomb.Length * 2]; + for (int i = 0; i < tomb.Length; i++) + { + tmp[i] = tomb[i]; + } + tmp[n] = ertek; + tomb = tmp; + } + n++; + } + + public T Kiolvas(int index) + { + if (index < 0) + { + throw new HibasIndexKivetel(); + } + return tomb[index]; + } + + public void Modosit(int index, T ertek) + { + if (index < 0) + { + throw new HibasIndexKivetel(); + } + if (index < tomb.Length) + { + tomb[index] = ertek; + } + else + { + T[] tmp = new T[tomb.Length * 2]; + for (int i = 0; i < tomb.Length; i++) + { + tmp[i] = tomb[i]; + } + tmp[n] = ertek; + tomb = tmp; + n++; + } + } + + public void Torol(T ertek) + { + T[] tmp = new T[tomb.Length]; + for (int i = tomb.Length; i > 0; i--) + { + if (i > n)//(ertek == tomb[i]) + { + continue; + } + tmp[i] = tomb[i]; + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + TombListaBejaro bejaro = new TombListaBejaro(tomb, n); + return bejaro; + } + } + public class TombListaBejaro : IEnumerator + { + T[] e; + int n; + int aktualisindex; + T current; + public T Current + { + get { return current; } + } + public TombListaBejaro(T[] e, int n) + { + this.n = n; + this.e = e; + aktualisindex = 0; + current = e[0]; + } + + object IEnumerator.Current => Current; + + public void Dispose() + { + throw new NotImplementedException(); + } + + public bool MoveNext() + { + if (aktualisindex < n - 1) + { + aktualisindex++; + return true; + } + else + { + return false; + } + } + + public void Reset() + { + aktualisindex = -1; + } + } +} \ No newline at end of file