Files
hello-algo/ru/codes/c/utils/vertex.h
Yudong Jin 772183705e Add ru version (#1865)
* Add Russian docs site baseline

* Add Russian localized codebase

* Polish Russian code wording

* Update ru code translation.

* Update code translation and chapter covers.

* Fix pythontutor extraction.

* Add README and landing page.

* placeholder of profiles

* Use figures of English version

* Remove chapter paperbook
2026-03-28 04:24:07 +08:00

50 lines
1.1 KiB
C

/**
* File: vertex.h
* Created Time: 2023-10-28
* Author: krahets (krahets@163.com)
*/
#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