From b8f1853b1a2f56cb1c04cb1add2b13ea49ee02d8 Mon Sep 17 00:00:00 2001 From: Lendaia Mirai Date: Sun, 5 Oct 2025 21:20:33 +0200 Subject: [PATCH] gugugaga --- ALGA/03_Tomb.cs | 100 +++++++++++++++++++++++------------------------- 1 file changed, 48 insertions(+), 52 deletions(-) diff --git a/ALGA/03_Tomb.cs b/ALGA/03_Tomb.cs index 5d63a54..3230bf0 100644 --- a/ALGA/03_Tomb.cs +++ b/ALGA/03_Tomb.cs @@ -111,9 +111,14 @@ namespace OE.ALGA.Adatszerkezetek { T[] tomb; int n = 0; + + public bool Ures + { + get { return n <= 0; } + } public TombLista() { - tomb = new T[n]; + tomb = new T[1]; } public int Elemszam @@ -123,35 +128,31 @@ namespace OE.ALGA.Adatszerkezetek public void Bejar(Action muvelet) { - throw new NotImplementedException(); + for (int i = 0; i < n; i++) + { + muvelet?.Invoke(tomb[i]); + } } public void Beszur(int index, T ertek) { - if (index < 0 || index > tomb.Length) + if (index < 0) { throw new HibasIndexKivetel(); } else { - if (index < tomb.Length && tomb[index] == null) + T[] tmp = new T[tomb.Length * 2]; + for (int i = 0; i < index; i++) { - tomb[index] = ertek; + tmp[i] = tomb[i]; } - else + tmp[index] = ertek; + for (int i = index + 1; i < tomb.Length; i++) { - 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 - 1]; - } - tomb = tmp; + tmp[i] = tomb[i - 1]; } + tomb = tmp; n++; } } @@ -171,39 +172,8 @@ namespace OE.ALGA.Adatszerkezetek { if (n < tomb.Length) { - tomb[n-1] = ertek; - } - else - { - T[] tmp = new T[tomb.Length * 2]; - for (int i = 0; i < tomb.Length; i++) - { - tmp[i] = tomb[i]; - } - tmp[n-1] = 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; + tomb[n] = ertek; + n++; } else { @@ -218,17 +188,43 @@ namespace OE.ALGA.Adatszerkezetek } } + public T Kiolvas(int index) + { + if (index < 0 || index >= tomb.Length) + { + throw new HibasIndexKivetel(); + } + return tomb[index]; + } + + public void Modosit(int index, T ertek) + { + if (index < 0 && index < tomb.Length) + { + throw new HibasIndexKivetel(); + } + else + { + tomb[index] = ertek; + } + } + public void Torol(T ertek) { + int m = n; T[] tmp = new T[tomb.Length]; - for (int i = tomb.Length; i > 0; i--) + int index = 0; + for (int i = 0; i < m; i++) { if (ertek.Equals(tomb[i])) { + n--; continue; } - tmp[i] = tomb[i]; + tmp[index] = tomb[i]; + index++; } + tomb = tmp; } IEnumerator IEnumerable.GetEnumerator()