2023-02-15 21:24:24 +08:00
|
|
|
/**
|
2023-04-24 04:11:18 +08:00
|
|
|
* File: Vertex.cs
|
2023-02-15 21:24:24 +08:00
|
|
|
* Created Time: 2023-02-06
|
|
|
|
* Author: zjkung1123 (zjkung1123@gmail.com), krahets (krahets@163.com)
|
|
|
|
*/
|
|
|
|
|
2023-04-24 04:20:51 +08:00
|
|
|
namespace hello_algo.utils;
|
2023-02-15 21:45:35 +08:00
|
|
|
|
2023-02-15 21:24:24 +08:00
|
|
|
/* 顶点类 */
|
2023-04-23 03:03:12 +08:00
|
|
|
public class Vertex {
|
2023-04-21 14:59:22 +08:00
|
|
|
public int val;
|
2023-04-23 03:03:12 +08:00
|
|
|
public Vertex(int val) {
|
2023-04-21 14:59:22 +08:00
|
|
|
this.val = val;
|
2023-02-15 21:24:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 输入值列表 vals ,返回顶点列表 vets */
|
2023-04-23 03:03:12 +08:00
|
|
|
public static Vertex[] ValsToVets(int[] vals) {
|
2023-02-15 21:24:24 +08:00
|
|
|
Vertex[] vets = new Vertex[vals.Length];
|
2023-04-23 03:03:12 +08:00
|
|
|
for (int i = 0; i < vals.Length; i++) {
|
2023-02-15 21:24:24 +08:00
|
|
|
vets[i] = new Vertex(vals[i]);
|
|
|
|
}
|
|
|
|
return vets;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 输入顶点列表 vets ,返回值列表 vals */
|
2023-04-23 03:03:12 +08:00
|
|
|
public static List<int> VetsToVals(List<Vertex> vets) {
|
2023-10-08 01:33:46 +08:00
|
|
|
List<int> vals = new();
|
2023-04-23 03:03:12 +08:00
|
|
|
foreach (Vertex vet in vets) {
|
2023-04-21 14:59:22 +08:00
|
|
|
vals.Add(vet.val);
|
2023-02-15 21:24:24 +08:00
|
|
|
}
|
|
|
|
return vals;
|
|
|
|
}
|
|
|
|
}
|