mirror of
https://github.com/Lendaia/oe-alga-feladatok.git
synced 2026-04-23 04:16:32 +01:00
lol
This commit is contained in:
234
ALGA/03_Tomb.cs
234
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<T> : Sor<T>
|
||||
{
|
||||
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<T> : Lista<T>, IEnumerable<T>
|
||||
{
|
||||
T[] tomb;
|
||||
int n = 0;
|
||||
public TombLista(int l)
|
||||
{
|
||||
tomb = new T[l];
|
||||
}
|
||||
|
||||
public int Elemszam
|
||||
{
|
||||
get { return n; }
|
||||
}
|
||||
|
||||
public void Bejar(Action<T> 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<T> 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<T> bejaro = new TombListaBejaro<T>(tomb, n);
|
||||
return bejaro;
|
||||
}
|
||||
}
|
||||
public class TombListaBejaro<T> : IEnumerator<T>
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user