Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace GrafTakBardzoŻeAżWcale
  8. {
  9. class Krawędź
  10. {
  11. public List<int> wierzchołek = new List<int>();
  12.  
  13. public Krawędź(int wierzchołek1, int wierzchołek2)
  14. {
  15. wierzchołek.Add(wierzchołek1);
  16. wierzchołek.Add(wierzchołek2);
  17. }
  18. }
  19.  
  20. class Program
  21. {
  22. static List<Krawędź> Konwertuj(int[,] G)
  23. {
  24. List<Krawędź> graf = new List<Krawędź>();
  25.  
  26. for (int i = 0; i < G.GetLength(0); i++)
  27. {
  28. for (int j = 0; j < G.GetLength(1); j++)
  29. {
  30. if (G[i, j] != 0 && i<j)
  31. { graf.Add(new Krawędź(i + 1, j+1)); }
  32. }
  33. }
  34. return graf;
  35. }
  36. static void Main(string[] args)
  37. {
  38. int[,] G =
  39. {
  40. { 0, 1, 0, 0, 1, 0 },
  41. { 1, 0, 1, 0, 1, 0 },
  42. { 0, 1, 0, 1, 0, 0 },
  43. { 0, 0, 1, 0, 1, 1 },
  44. { 1, 1, 0, 1, 0, 0 },
  45. { 0, 0, 0, 1, 0, 0 }
  46. };
  47. List<Krawędź> graf = Konwertuj(G);
  48. for (int i = 0; i < graf.Count; i++)
  49. {
  50. Console.Write(i+1 + " (");
  51. foreach (int item in graf[i].wierzchołek)
  52. {
  53. Console.Write(item+ " ");
  54. }
  55. Console.Write(")\n");
  56. }
  57. Console.ReadKey();
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement