mirror of
https://github.com/krahets/hello-algo.git
synced 2026-08-30 20:07:14 +00:00
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
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* 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
|
||||
Reference in New Issue
Block a user