mirror of
https://github.com/Lendaia/oe-alga-feladatok.git
synced 2026-04-23 12:26:07 +01:00
gugugaga
This commit is contained in:
100
ALGA/03_Tomb.cs
100
ALGA/03_Tomb.cs
@@ -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,35 +128,31 @@ 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)
|
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];
|
tmp[i] = tomb[i - 1];
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
tomb = tmp;
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -171,39 +172,8 @@ namespace OE.ALGA.Adatszerkezetek
|
|||||||
{
|
{
|
||||||
if (n < tomb.Length)
|
if (n < tomb.Length)
|
||||||
{
|
{
|
||||||
tomb[n-1] = ertek;
|
tomb[n] = ertek;
|
||||||
}
|
n++;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
else
|
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)
|
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()
|
||||||
|
|||||||
Reference in New Issue
Block a user