Created
March 10, 2022 07:02
-
-
Save jetobe95/171702c8d523e650248dd31075f71868 to your computer and use it in GitHub Desktop.
Getting started with graphs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
final oVertice1 = Vertice(1); | |
final oVertice2 = Vertice(2); | |
final oVertice3 = Vertice(3); | |
final oVertice4 = Vertice(4); | |
final oVertice5 = Vertice(5); | |
final oVertice6 = Vertice(6); | |
oVertice6.add(oVertice4); | |
oVertice4 | |
..add(oVertice5) | |
..add(oVertice3); | |
oVertice5 | |
..add(oVertice1) | |
..add(oVertice2); | |
oVertice2.add(oVertice1); | |
oVertice3.add(oVertice2); | |
caminar(oVertice6); | |
} | |
void caminar(Vertice vertice,[String sangria = '\t']) { | |
print('${vertice.valor}'+ sangria); | |
for (Vertice v in vertice.aristas) { | |
caminar(v,sangria + '\t'); | |
} | |
} | |
class Vertice { | |
final int valor; | |
final List<Vertice> aristas = []; | |
Vertice( | |
this.valor, | |
); | |
void add(Vertice vertice) { | |
aristas.add(vertice); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment