This commit is contained in:
Lendaia Mirai
2025-10-05 21:20:33 +02:00
parent 56ab53ccc3
commit b8f1853b1a

View File

@@ -111,9 +111,14 @@ namespace OE.ALGA.Adatszerkezetek
{ {
T[] tomb; T[] tomb;
int n = 0; int n = 0;
public bool Ures
{
get { return n <= 0; }
}
public TombLista() public TombLista()
{ {
tomb = new T[n]; tomb = new T[1];
} }
public int Elemszam public int Elemszam
@@ -123,22 +128,19 @@ namespace OE.ALGA.Adatszerkezetek
public void Bejar(Action<T> muvelet) public void Bejar(Action<T> muvelet)
{ {
throw new NotImplementedException(); for (int i = 0; i < n; i++)
{
muvelet?.Invoke(tomb[i]);
}
} }
public void Beszur(int index, T ertek) public void Beszur(int index, T ertek)
{ {
if (index < 0 || index > tomb.Length) if (index < 0)
{ {
throw new HibasIndexKivetel(); throw new HibasIndexKivetel();
} }
else else
{
if (index < tomb.Length && tomb[index] == null)
{
tomb[index] = ertek;
}
else
{ {
T[] tmp = new T[tomb.Length * 2]; T[] tmp = new T[tomb.Length * 2];
for (int i = 0; i < index; i++) for (int i = 0; i < index; i++)
@@ -151,7 +153,6 @@ namespace OE.ALGA.Adatszerkezetek
tmp[i] = tomb[i - 1]; tmp[i] = tomb[i - 1];
} }
tomb = tmp; tomb = tmp;
}
n++; n++;
} }
} }
@@ -171,40 +172,9 @@ namespace OE.ALGA.Adatszerkezetek
{ {
if (n < tomb.Length) if (n < tomb.Length)
{ {
tomb[n-1] = ertek; 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-1] = ertek;
tomb = tmp;
}
n++; 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 else
{ {
T[] tmp = new T[tomb.Length * 2]; T[] tmp = new T[tomb.Length * 2];
@@ -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) public void Torol(T ertek)
{ {
int m = n;
T[] tmp = new T[tomb.Length]; 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])) if (ertek.Equals(tomb[i]))
{ {
n--;
continue; continue;
} }
tmp[i] = tomb[i]; tmp[index] = tomb[i];
index++;
} }
tomb = tmp;
} }
IEnumerator IEnumerable.GetEnumerator() IEnumerator IEnumerable.GetEnumerator()