mirror of
https://github.com/Lendaia/oe-alga-feladatok.git
synced 2026-04-23 04:16:32 +01:00
sendluckpls
This commit is contained in:
@@ -139,14 +139,49 @@ namespace OE.ALGA.Adatszerkezetek
|
||||
return M[honnan, hova];
|
||||
}
|
||||
}
|
||||
public class GrafBejaras<T>
|
||||
public static class GrafBejaras
|
||||
{
|
||||
public static Halmaz<V> SzelessegiBejaras<V, E>(Graf<V, E> g, V start, Action<V> muvelet) where V : IComparable
|
||||
{
|
||||
FaHalmaz<int> fahalmaz = new FaHalmaz<int>();
|
||||
int j = 0;
|
||||
g.Csucsok.Bejar(muvelet);
|
||||
//eheheheee
|
||||
LancoltSor<V> sor = new LancoltSor<V>();
|
||||
FaHalmaz<V> fahalmaz = new FaHalmaz<V>();
|
||||
sor.Sorba(start);
|
||||
fahalmaz.Beszur(start);
|
||||
while(!sor.Ures)
|
||||
{
|
||||
V k = sor.Sorbol();
|
||||
muvelet(k);
|
||||
FaHalmaz<V> halmaz = (FaHalmaz<V>)g.Szomszedai(k);
|
||||
halmaz.Bejar(x =>
|
||||
{
|
||||
if (!fahalmaz.Eleme(x))
|
||||
{
|
||||
sor.Sorba(x);
|
||||
fahalmaz.Beszur(x);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return fahalmaz;
|
||||
}
|
||||
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);
|
||||
return fahalmaz;
|
||||
|
||||
}
|
||||
private static void MelysegiBejarasRekurzio<V,E>(Graf<V,E> g, V k, Halmaz<V> F, Action<V> muvelet) where V: IComparable
|
||||
{
|
||||
F.Beszur(k);
|
||||
FaHalmaz<V> halmaz = (FaHalmaz<V>)g.Szomszedai(k);
|
||||
halmaz.Bejar(x =>
|
||||
{
|
||||
if (!F.Eleme(x))
|
||||
{
|
||||
MelysegiBejarasRekurzio(g, x, F, muvelet);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user