Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace GrafTakBardzoŻeAżWcale
- {
- class Krawędź
- {
- public List<int> wierzchołek = new List<int>();
- public Krawędź(int wierzchołek1, int wierzchołek2)
- {
- wierzchołek.Add(wierzchołek1);
- wierzchołek.Add(wierzchołek2);
- }
- }
- class Program
- {
- static List<Krawędź> Konwertuj(int[,] G)
- {
- List<Krawędź> graf = new List<Krawędź>();
- for (int i = 0; i < G.GetLength(0); i++)
- {
- for (int j = 0; j < G.GetLength(1); j++)
- {
- if (G[i, j] != 0 && i<j)
- { graf.Add(new Krawędź(i + 1, j+1)); }
- }
- }
- return graf;
- }
- static void Main(string[] args)
- {
- int[,] G =
- {
- { 0, 1, 0, 0, 1, 0 },
- { 1, 0, 1, 0, 1, 0 },
- { 0, 1, 0, 1, 0, 0 },
- { 0, 0, 1, 0, 1, 1 },
- { 1, 1, 0, 1, 0, 0 },
- { 0, 0, 0, 1, 0, 0 }
- };
- List<Krawędź> graf = Konwertuj(G);
- for (int i = 0; i < graf.Count; i++)
- {
- Console.Write(i+1 + " (");
- foreach (int item in graf[i].wierzchołek)
- {
- Console.Write(item+ " ");
- }
- Console.Write(")\n");
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement