mirror of
https://github.com/Lendaia/oe-alga-feladatok.git
synced 2026-04-23 04:16:32 +01:00
194 lines
3.4 KiB
C#
194 lines
3.4 KiB
C#
using System;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace OE.ALGA.Adatszerkezetek;
|
|
|
|
public class LancElem<T>
|
|
{
|
|
public T tart;
|
|
public LancElem<T>? kov;
|
|
public LancElem<T>? elozo;
|
|
|
|
public LancElem(T tart, LancElem<T>? kov, LancElem<T>? elozo)
|
|
{
|
|
this.tart = tart;
|
|
this.kov = kov;
|
|
this.elozo = elozo;
|
|
}
|
|
}
|
|
public class LancoltVerem<T> : Verem<T>
|
|
{
|
|
LancElem<T>? fej;
|
|
LancElem<T>? teteje;
|
|
public LancoltVerem()
|
|
{
|
|
}
|
|
public void Felszabadit()
|
|
{
|
|
|
|
}
|
|
public bool Ures
|
|
{
|
|
get { return fej == null; }
|
|
}
|
|
|
|
public T Felso()
|
|
{
|
|
if (Ures)
|
|
{
|
|
throw new NincsElemKivetel();
|
|
}
|
|
else
|
|
{
|
|
LancElem<T>? tmp = fej;
|
|
while (tmp.kov != null)
|
|
{
|
|
tmp = tmp.kov;
|
|
}
|
|
teteje = tmp;
|
|
return tmp.tart;
|
|
}
|
|
}
|
|
|
|
public void Verembe(T ertek)
|
|
{
|
|
if (Ures)
|
|
{
|
|
fej.kov = new LancElem<T>(ertek, null, fej);
|
|
}
|
|
else
|
|
{
|
|
teteje.kov = new LancElem<T>(ertek, null, teteje);
|
|
}
|
|
}
|
|
|
|
public T Verembol()
|
|
{
|
|
if (Ures)
|
|
{
|
|
throw new NincsElemKivetel();
|
|
}
|
|
else
|
|
{
|
|
T ertek = Felso();
|
|
teteje.elozo.kov = null;
|
|
return ertek;
|
|
}
|
|
}
|
|
}
|
|
public class LancoltSor<T> : Sor<T>
|
|
{
|
|
LancElem<T>? fej;
|
|
LancElem<T>? vege;
|
|
public bool Ures
|
|
{
|
|
get { return (fej == null && vege == null); }
|
|
}
|
|
public LancoltSor()
|
|
{
|
|
|
|
}
|
|
public void Felszabadit()
|
|
{
|
|
|
|
}
|
|
public T Elso()
|
|
{
|
|
return fej.tart;
|
|
}
|
|
|
|
public void Sorba(T ertek)
|
|
{
|
|
if (Ures)
|
|
{
|
|
fej.tart = ertek;
|
|
}
|
|
else
|
|
{
|
|
LancElem<T>? tmp = fej;
|
|
while (tmp.kov != null)
|
|
{
|
|
tmp = tmp.kov;
|
|
}
|
|
tmp.kov = new LancElem<T>(ertek, null, tmp);
|
|
vege = tmp.kov;
|
|
}
|
|
}
|
|
|
|
public T Sorbol()
|
|
{
|
|
if (Ures)
|
|
{
|
|
throw new NincsElemKivetel();
|
|
}
|
|
else
|
|
{
|
|
T ertek = vege.tart;
|
|
vege = vege.elozo;
|
|
vege.kov = null;
|
|
return ertek;
|
|
}
|
|
}
|
|
}
|
|
public class LancoltLista<T> : Lista<T>
|
|
{
|
|
int n;
|
|
LancElem<T>? fej;
|
|
|
|
public int Elemszam
|
|
{
|
|
get { return n; }
|
|
}
|
|
public LancoltLista()
|
|
{
|
|
|
|
}
|
|
public void Felszabadit()
|
|
{
|
|
|
|
}
|
|
|
|
public void Bejar(Action<T> muvelet)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public void Beszur(int index, T ertek)
|
|
{
|
|
LancElem<T>? xd = Indexedik(index).elozo;
|
|
xd.kov = new LancElem<T>(ertek, Indexedik(index), xd);
|
|
n++;
|
|
}
|
|
|
|
public void Hozzafuz(T ertek)
|
|
{
|
|
LancElem<T> asd = Indexedik(n);
|
|
asd.kov = new LancElem<T>(ertek, null, asd);
|
|
n++;
|
|
}
|
|
|
|
public T Kiolvas(int index)
|
|
{
|
|
return Indexedik(index).tart;
|
|
}
|
|
|
|
public void Modosit(int index, T ertek)
|
|
{
|
|
Indexedik(index).tart = ertek;
|
|
}
|
|
|
|
public void Torol(T ertek)
|
|
{
|
|
//ez gonixd
|
|
}
|
|
private LancElem<T> Indexedik(int index)
|
|
{
|
|
LancElem<T>? tmp = fej;
|
|
for (int i = 0; i < index; i++)
|
|
{
|
|
tmp = tmp.kov;
|
|
}
|
|
return tmp;
|
|
}
|
|
}
|