【发布时间】:2019-11-25 00:46:36
【问题描述】:
这是对a question 的重述,现已被删除。我认为这是一个有趣的问题。问题的输入是一个二元元组数组,每个元组代表一条连接两个抽象顶点的抽象边。所需的输出是连接顶点的数组。顶点可以是任何类型,不一定是空间中的点,因此是“抽象”名称。预计不会以任何方式对该数组进行排序。实际上,这些类型甚至没有可比性。我们只能比较它们是否相等。
输入输出示例:
var input = new[] { ('a', 'b'), ('c', 'b'), ('a', 'c') };
var output = new[] { 'a', 'b', 'c' };
var input = new[] { ("a", "b"), ("a", "b") };
var output = new[] { "a", "b" };
var input = new[] { (true, true) };
var output = new[] { true };
var input = new[] { (1, 2), (4, 3), (3, 2), (1, 4) };
var output = new[] { 1, 2, 3, 4 };
var input = new[] { (1, 2), (2, 3), (3, 4) };
var output = new InvalidDataException(
"Vertices [1, 4] are not connected with exactly 2 other vertices.");
var input = new[] { (1, 2), (2, 1), (3, 4), (4, 3) };
var output = new InvalidDataException(
"Vertices [3, 4] are not connected with the rest of the graph.");
方法签名:
public static T[] GetVerticesFromEdges<T>((T, T)[] edges,
IEqualityComparer<T> comparer);
【问题讨论】: