whwwwwwww

This commit is contained in:
Lendaia Mirai
2025-12-10 22:37:56 +01:00
parent 45adc0f064
commit d82decbfa2
8 changed files with 734 additions and 432 deletions

View File

@@ -163,8 +163,8 @@ namespace OE.ALGA.Adatszerkezetek
}
public class LancoltLista<T> : Lista<T>, IEnumerable<T>
{
int n;
LancElem<T>? fej;
protected int n;
protected LancElem<T>? fej;
public int Elemszam
{
@@ -283,7 +283,7 @@ namespace OE.ALGA.Adatszerkezetek
}
}
}
private LancElem<T> Indexedik(int index)
protected LancElem<T> Indexedik(int index)
{
LancElem<T>? tmp = fej;
for (int i = 0; i < index; i++)
@@ -350,4 +350,38 @@ namespace OE.ALGA.Adatszerkezetek
aktualisElem = fej;
}
}
public class KorlatoltLancoltLista<T> :LancoltLista<T> where T: IComparable
{
public LancElem<T> min
{
get
{
LancElem<T> cur = this.fej;
for (int i = 0; i < n; i++)
{
if(Indexedik(i).tart.CompareTo(cur.tart) > 0)
{
cur = Indexedik(i);
}
}
return cur;
}
}
public LancElem<T> max
{
get
{
LancElem<T> cur = this.fej;
for (int i = 0; i < n; i++)
{
if(Indexedik(i).tart.CompareTo(cur.tart) < 0)
{
cur = Indexedik(i);
}
}
return cur;
}
}
}
}

View File

@@ -61,13 +61,14 @@ public class FaHalmaz<T> : Halmaz<T> where T : IComparable
}
else
{
if (p.tart.CompareTo(ertek) > 0)
int asd = ertek.CompareTo(p.tart);
if (asd < 0)
{
p.bal = ReszfabaBeszur(p.bal, ertek);
}
else
{
if (p.tart.CompareTo(ertek) < 0)
if (asd > 0)
{
p.jobb = ReszfabaBeszur(p.jobb, ertek);
}

View File

@@ -80,7 +80,7 @@ namespace OE.ALGA.Adatszerkezetek
get
{
FaHalmaz<int> fahalmaz = new FaHalmaz<int>();
for (int i = 0; i < n-1; i++)
for (int i = 0; i < n; i++)
{
fahalmaz.Beszur(i);
}
@@ -139,7 +139,7 @@ namespace OE.ALGA.Adatszerkezetek
return M[honnan, hova];
}
}
public static class GrafBejaras
public static class GrafBejarasok
{
public static Halmaz<V> SzelessegiBejaras<V, E>(Graf<V, E> g, V start, Action<V> muvelet) where V : IComparable
{
@@ -167,21 +167,24 @@ namespace OE.ALGA.Adatszerkezetek
public static Halmaz<V> MelysegiBejaras<V,E>(Graf<V, E> g, V start, Action<V> muvelet) where V : IComparable
{
Halmaz<V> fahalmaz = new FaHalmaz<V>();
MelysegiBejarasRekurzio(g, start, fahalmaz, muvelet);
fahalmaz.Beszur(start);
MelysegiBejarasRekurzio(g, start, muvelet, fahalmaz);
return fahalmaz;
}
private static void MelysegiBejarasRekurzio<V,E>(Graf<V,E> g, V k, Halmaz<V> F, Action<V> muvelet) where V: IComparable
private static void MelysegiBejarasRekurzio<V,E>(Graf<V,E> g, V k, Action<V> muvelet, Halmaz<V> F) where V: IComparable
{
F.Beszur(k);
muvelet(k);
FaHalmaz<V> halmaz = (FaHalmaz<V>)g.Szomszedai(k);
halmaz.Bejar(x =>
{
if (!F.Eleme(x))
{
MelysegiBejarasRekurzio(g, x, F, muvelet);
F.Beszur(x);
MelysegiBejarasRekurzio(g, x, muvelet, F);
}
});
}
}
}
}

View File

@@ -2,5 +2,163 @@
namespace OE.ALGA.Adatszerkezetek
{
// 11. heti labor feladat - Tesztek: 11_KupacTesztek.cs
public class Kupac<T>
{
protected T[] E;
protected int n;
protected Func<T, T, bool> nagyobbPrioritas;
public Kupac(T[] E, int n, Func<T, T, bool> nagyobbPrioritas)
{
this.E = E;
this.n = n;
this.nagyobbPrioritas = nagyobbPrioritas;
KupacotEpit();
}
public static int Bal(int i)
{
return 2 * i + 1;
}
public static int Jobb(int i)
{
return 2 * i + 2;
}
public static int Szulo(int i)
{
return (i - 1) / 2;
}
protected void Kupacol(int i)
{
bool vege = false;
while (!vege)
{
int bal = Bal(i);
int jobb = Jobb(i);
int legnagyobb = i;
if (bal < n && nagyobbPrioritas(E[bal], E[legnagyobb]))
legnagyobb = bal;
if (jobb < n && nagyobbPrioritas(E[jobb], E[legnagyobb]))
legnagyobb = jobb;
if (legnagyobb != i)
{
T csere = E[i];
E[i] = E[legnagyobb];
E[legnagyobb] = csere;
i = legnagyobb;
}
else
{
vege = true;
}
}
}
protected void KupacotEpit()
{
for (int i = n / 2 - 1; i >= 0; i--)
Kupacol(i);
}
}
public class KupacRendezes<T> : Kupac<T> where T : IComparable
{
public KupacRendezes(T[] A)
: base(A, A.Length, (x, y) => x.CompareTo(y) > 0)
{
}
public void Rendezes()
{
int eredetiN = n;
for (int i = n - 1; i >= 1; i--)
{
T csere = E[0];
E[0] = E[i];
E[i] = csere;
n--;
Kupacol(0);
}
n = eredetiN;
}
}
public class KupacPrioritasosSor<T> : Kupac<T>, PrioritasosSor<T>
{
public KupacPrioritasosSor(int meret, Func<T, T, bool> nagyobbPrioritas)
: base(new T[meret], 0, nagyobbPrioritas)
{
}
public bool Ures
{
get { return n == 0; }
}
private void KulcsotFelvisz(int i)
{
while (i > 0 && nagyobbPrioritas(E[i], E[Szulo(i)]))
{
int s = Szulo(i);
T csere = E[i];
E[i] = E[s];
E[s] = csere;
i = s;
}
}
public void Sorba(T ertek)
{
if (n == E.Length)
throw new NincsHelyKivetel();
E[n] = ertek;
KulcsotFelvisz(n);
n++;
}
public T Sorbol()
{
if (Ures)
throw new NincsElemKivetel();
T max = E[0];
E[0] = E[n - 1];
n--;
if (n > 0)
Kupacol(0);
return max;
}
public T Elso()
{
if (Ures)
throw new NincsElemKivetel();
return E[0];
}
public void Frissit(T ertek)
{
int poz = -1;
for (int i = 0; i < n && poz == -1; i++)
{
if (Equals(E[i], ertek))
poz = i;
}
if (poz == -1)
throw new NincsElemKivetel();
KulcsotFelvisz(poz);
Kupacol(poz);
}
}
}

View File

@@ -2,5 +2,110 @@
namespace OE.ALGA.Adatszerkezetek
{
// 12. heti labor feladat - Tesztek: 12_SulyozottGrafTesztek.cs
public class SulyozottEgeszGrafEl : EgeszGrafEl, SulyozottGrafEl<int>
{
public float Suly {get;}
public SulyozottEgeszGrafEl(int honnan, int hova, float suly) : base(honnan, hova)
{
Suly = suly;
}
}
public class CsucsmatrixSulyozottEgeszGraf : SulyozottGraf<int, SulyozottEgeszGrafEl>
{
int n;
float[,] M;
public int CsucsokSzama {get{return n;}}
public int ElekSzama
{
get
{
int elek = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (M[i,j] != null)
{
elek++;
}
}
}
return elek;
}
}
public CsucsmatrixSulyozottEgeszGraf(int n)
{
this.n = n;
M = new float[n,n];
}
public Halmaz<int> Csucsok
{
get
{
FaHalmaz<int> fahalmaz = new FaHalmaz<int>();
for (int i = 0; i < n; i++)
{
fahalmaz.Beszur(i);
}
return fahalmaz;
}
}
public Halmaz<SulyozottEgeszGrafEl> Elek
{
get
{
FaHalmaz<SulyozottEgeszGrafEl> fahalmaz = new FaHalmaz<SulyozottEgeszGrafEl>();
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (M[i,j] != null)
{
SulyozottEgeszGrafEl egeszgrafel = new SulyozottEgeszGrafEl(i, j, M[i,j]);
fahalmaz.Beszur(egeszgrafel);
}
}
}
return fahalmaz;
}
}
public float Suly(int honnan, int hova)
{
if(M[honnan, hova] != null)
{
return M[honnan, hova];
}
else
{
throw new NincsElKivetel();
}
}
public Halmaz<int> Szomszedai(int csucs)
{
FaHalmaz<int> fahalmaz = new FaHalmaz<int>();
for (int i = 0; i < n; i++)
{
if (M[csucs, i] != null)
{
fahalmaz.Beszur(i);
}
}
return fahalmaz;
}
public void UjEl(int honnan, int hova, float suly)
{
M[honnan, hova] = suly;
}
public bool VezetEl(int honnan, int hova)
{
return (M[honnan, hova]!= null);
}
}
}