Created by Visual Studio 2013 Author Emel yanov Konstantin Date 22 02

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* Created by Visual Studio 2013
* Author: Emel'yanov Konstantin
* Date: 22.02.15
* Time: 17:02
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Graph
{
class Graph{
public int[] arr_from = new int[] { 2, 4, 1, 2, 4, 3 };
public int[] arr_to = new int[] { 4, 3, 2, 5, 5, 2 };
public Dictionary<int, string> list = new Dictionary<int, string>();
public void sort()
{
int temp;
for (int i = 0; i < arr_from.Length; ++i)
{
for (int j = i + 1; j < arr_from.Length; ++j)
{
if (arr_from[i] > arr_from[j])
{
// Sorting "arr_from" array
temp = arr_from[i];
arr_from[i] = arr_from[j];
arr_from[j] = temp;
// Sorting "arr_to" array
temp = arr_to[i];
arr_to[i] = arr_to[j];
arr_to[j] = temp;
}
}
}
}
public void getList()
{
int col = 0;
foreach(int data in arr_from)
{
if(list.ContainsKey(data) == true)
{
string value = list[data] + "," + arr_to[col].ToString();
list.Remove(data);
list.Add(data, value);
}
else
{
list.Add(data, arr_to[col].ToString());
}
col++;
}
}
}
class Program
{
static void Main(string[] args)
{
Graph graph = new Graph();
graph.sort();
graph.getList();
foreach(int ass in graph.list.Keys)
{
Console.WriteLine("{0} [{1}]", ass, graph.list[ass]);
}
Console.ReadKey();
}
}
}