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;
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<T> 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()