Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. public Graf()
  2. {
  3. this.nodes = new List<Node>();
  4. this.krawedzie = new List<Krawedz>();
  5. }
  6.  
  7. public List<Krawedz> ZwrocKrawedzie(Node n)
  8. {
  9. List<Krawedz> zbior = new List<Krawedz>();
  10. for (int i = 0; i < this.krawedzie.Count; i++)
  11. {
  12. var k = this.krawedzie[i];
  13. if ((k.start == n) || (k.koniec == n))
  14. zbior.Add(k);
  15. }
  16. return zbior;
  17. }
  18.  
  19. public void PrzejscieGrafu(Node start)
  20. {
  21. this.odwiedzone = new List<Node>();
  22. this.DFS(start);
  23. }
  24.  
  25. public void DFS(Node n)
  26. {
  27. if (this.odwiedzone.Contains(n))
  28. {
  29. return;
  30. }
  31. this.odwiedzone.Add(n);
  32. var krawedzieOb = this.ZwrocKrawedzie(n);
  33. foreach (var k in krawedzieOb)
  34. {
  35. var drugi = k.ZnajdzDrugi(n);
  36. DFS(drugi);
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement