2023-10-29 19:52:19 +08:00
|
|
|
/**
|
|
|
|
* File: vertex.h
|
|
|
|
* Created Time: 2023-10-28
|
2024-02-07 22:21:18 +08:00
|
|
|
* Author: krahets (krahets@163.com)
|
2023-10-29 19:52:19 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef VERTEX_H
|
|
|
|
#define VERTEX_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* 顶点结构体 */
|
|
|
|
typedef struct {
|
|
|
|
int val;
|
|
|
|
} Vertex;
|
|
|
|
|
|
|
|
/* 构造函数,初始化一个新节点 */
|
|
|
|
Vertex *newVertex(int val) {
|
|
|
|
Vertex *vet;
|
|
|
|
vet = (Vertex *)malloc(sizeof(Vertex));
|
|
|
|
vet->val = val;
|
|
|
|
return vet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 将值数组转换为顶点数组 */
|
|
|
|
Vertex **valsToVets(int *vals, int size) {
|
|
|
|
Vertex **vertices = (Vertex **)malloc(size * sizeof(Vertex *));
|
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
vertices[i] = newVertex(vals[i]);
|
|
|
|
}
|
|
|
|
return vertices;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 将顶点数组转换为值数组 */
|
|
|
|
int *vetsToVals(Vertex **vertices, int size) {
|
|
|
|
int *vals = (int *)malloc(size * sizeof(int));
|
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
vals[i] = vertices[i]->val;
|
|
|
|
}
|
|
|
|
return vals;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // VERTEX_H
|