mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-18 01:36:07 +00:00
Re-translate the Japanese version (#1871)
* Retranslate Japanese docs with GPT-5.4 * Retranslate Japanese code with GPT-5.4
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
add_executable(utils
|
||||
common_test.c
|
||||
common.h print_util.h
|
||||
list_node.h tree_node.h
|
||||
uthash.h)
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* File: common.h
|
||||
* Created Time: 2022-12-20
|
||||
* Author: MolDuM (moldum@163.com)、Reanon (793584285@qq.com)
|
||||
*/
|
||||
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "list_node.h"
|
||||
#include "print_util.h"
|
||||
#include "tree_node.h"
|
||||
#include "vertex.h"
|
||||
|
||||
// hash table lib
|
||||
#include "uthash.h"
|
||||
|
||||
#include "vector.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // COMMON_H
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* File: include_test.c
|
||||
* Created Time: 2023-01-10
|
||||
* Author: Reanon (793584285@qq.com)
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
|
||||
void testListNode() {
|
||||
int nums[] = {2, 3, 5, 6, 7};
|
||||
int size = sizeof(nums) / sizeof(int);
|
||||
ListNode *head = arrToLinkedList(nums, size);
|
||||
printLinkedList(head);
|
||||
}
|
||||
|
||||
void testTreeNode() {
|
||||
int nums[] = {1, 2, 3, INT_MAX, 5, 6, INT_MAX};
|
||||
int size = sizeof(nums) / sizeof(int);
|
||||
TreeNode *root = arrayToTree(nums, size);
|
||||
|
||||
// print tree
|
||||
printTree(root);
|
||||
|
||||
// tree to arr
|
||||
int *arr = treeToArray(root, &size);
|
||||
printArray(arr, size);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
printf("==testListNode==\n");
|
||||
testListNode();
|
||||
printf("==testTreeNode==\n");
|
||||
testTreeNode();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* File: list_node.h
|
||||
* Created Time: 2023-01-09
|
||||
* Author: Reanon (793584285@qq.com)
|
||||
*/
|
||||
|
||||
#ifndef LIST_NODE_H
|
||||
#define LIST_NODE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* 連結リストノード構造体 */
|
||||
typedef struct ListNode {
|
||||
int val; // ノード値
|
||||
struct ListNode *next; // 次のノードへの参照
|
||||
} ListNode;
|
||||
|
||||
/* コンストラクタ。新しいノードを初期化する */
|
||||
ListNode *newListNode(int val) {
|
||||
ListNode *node;
|
||||
node = (ListNode *)malloc(sizeof(ListNode));
|
||||
node->val = val;
|
||||
node->next = NULL;
|
||||
return node;
|
||||
}
|
||||
|
||||
/* 配列をデシリアライズして連結リストに変換する */
|
||||
ListNode *arrToLinkedList(const int *arr, size_t size) {
|
||||
if (size <= 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ListNode *dummy = newListNode(0);
|
||||
ListNode *node = dummy;
|
||||
for (int i = 0; i < size; i++) {
|
||||
node->next = newListNode(arr[i]);
|
||||
node = node->next;
|
||||
}
|
||||
return dummy->next;
|
||||
}
|
||||
|
||||
/* 連結リストに割り当てたメモリを解放する */
|
||||
void freeMemoryLinkedList(ListNode *cur) {
|
||||
// メモリを解放する
|
||||
ListNode *pre;
|
||||
while (cur != NULL) {
|
||||
pre = cur;
|
||||
cur = cur->next;
|
||||
free(pre);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // LIST_NODE_H
|
||||
@@ -0,0 +1,131 @@
|
||||
/**
|
||||
* File: print_util.h
|
||||
* Created Time: 2022-12-21
|
||||
* Author: MolDum (moldum@163.com), Reanon (793584285@qq.com)
|
||||
*/
|
||||
|
||||
#ifndef PRINT_UTIL_H
|
||||
#define PRINT_UTIL_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "list_node.h"
|
||||
#include "tree_node.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* 配列を出力する */
|
||||
void printArray(int arr[], int size) {
|
||||
if (arr == NULL || size == 0) {
|
||||
printf("[]");
|
||||
return;
|
||||
}
|
||||
printf("[");
|
||||
for (int i = 0; i < size - 1; i++) {
|
||||
printf("%d, ", arr[i]);
|
||||
}
|
||||
printf("%d]\n", arr[size - 1]);
|
||||
}
|
||||
|
||||
/* 配列を出力する */
|
||||
void printArrayFloat(float arr[], int size) {
|
||||
if (arr == NULL || size == 0) {
|
||||
printf("[]");
|
||||
return;
|
||||
}
|
||||
printf("[");
|
||||
for (int i = 0; i < size - 1; i++) {
|
||||
printf("%.2f, ", arr[i]);
|
||||
}
|
||||
printf("%.2f]\n", arr[size - 1]);
|
||||
}
|
||||
|
||||
/* 連結リストを出力 */
|
||||
void printLinkedList(ListNode *node) {
|
||||
if (node == NULL) {
|
||||
return;
|
||||
}
|
||||
while (node->next != NULL) {
|
||||
printf("%d -> ", node->val);
|
||||
node = node->next;
|
||||
}
|
||||
printf("%d\n", node->val);
|
||||
}
|
||||
|
||||
typedef struct Trunk {
|
||||
struct Trunk *prev;
|
||||
char *str;
|
||||
} Trunk;
|
||||
|
||||
Trunk *newTrunk(Trunk *prev, char *str) {
|
||||
Trunk *trunk = (Trunk *)malloc(sizeof(Trunk));
|
||||
trunk->prev = prev;
|
||||
trunk->str = (char *)malloc(sizeof(char) * 10);
|
||||
strcpy(trunk->str, str);
|
||||
return trunk;
|
||||
}
|
||||
|
||||
void showTrunks(Trunk *trunk) {
|
||||
if (trunk == NULL) {
|
||||
return;
|
||||
}
|
||||
showTrunks(trunk->prev);
|
||||
printf("%s", trunk->str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 二分木を出力
|
||||
* This tree printer is borrowed from TECHIE DELIGHT
|
||||
* https://www.techiedelight.com/c-program-print-binary-tree/
|
||||
*/
|
||||
void printTreeHelper(TreeNode *node, Trunk *prev, bool isRight) {
|
||||
if (node == NULL) {
|
||||
return;
|
||||
}
|
||||
char *prev_str = " ";
|
||||
Trunk *trunk = newTrunk(prev, prev_str);
|
||||
printTreeHelper(node->right, trunk, true);
|
||||
if (prev == NULL) {
|
||||
trunk->str = "———";
|
||||
} else if (isRight) {
|
||||
trunk->str = "/———";
|
||||
prev_str = " |";
|
||||
} else {
|
||||
trunk->str = "\\———";
|
||||
prev->str = prev_str;
|
||||
}
|
||||
showTrunks(trunk);
|
||||
printf("%d\n", node->val);
|
||||
|
||||
if (prev != NULL) {
|
||||
prev->str = prev_str;
|
||||
}
|
||||
trunk->str = " |";
|
||||
|
||||
printTreeHelper(node->left, trunk, false);
|
||||
}
|
||||
|
||||
/* 二分木を出力 */
|
||||
void printTree(TreeNode *root) {
|
||||
printTreeHelper(root, NULL, false);
|
||||
}
|
||||
|
||||
/* ヒープを出力 */
|
||||
void printHeap(int arr[], int size) {
|
||||
TreeNode *root;
|
||||
printf("ヒープの配列表現:");
|
||||
printArray(arr, size);
|
||||
printf("ヒープの木構造表現:\n");
|
||||
root = arrayToTree(arr, size);
|
||||
printTree(root);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // PRINT_UTIL_H
|
||||
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* File: tree_node.h
|
||||
* Created Time: 2023-01-09
|
||||
* Author: Reanon (793584285@qq.com)
|
||||
*/
|
||||
|
||||
#ifndef TREE_NODE_H
|
||||
#define TREE_NODE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#define MAX_NODE_SIZE 5000
|
||||
|
||||
/* 二分木ノード構造体 */
|
||||
typedef struct TreeNode {
|
||||
int val; // ノード値
|
||||
int height; // ノードの高さ
|
||||
struct TreeNode *left; // 左の子ノードへのポインタ
|
||||
struct TreeNode *right; // 右の子ノードへのポインタ
|
||||
} TreeNode;
|
||||
|
||||
/* コンストラクタ */
|
||||
TreeNode *newTreeNode(int val) {
|
||||
TreeNode *node;
|
||||
|
||||
node = (TreeNode *)malloc(sizeof(TreeNode));
|
||||
node->val = val;
|
||||
node->height = 0;
|
||||
node->left = NULL;
|
||||
node->right = NULL;
|
||||
return node;
|
||||
}
|
||||
|
||||
// シリアライズの符号化規則は以下を参照:
|
||||
// https://www.hello-algo.com/chapter_tree/array_representation_of_tree/
|
||||
// 二分木の配列表現:
|
||||
// [1, 2, 3, 4, None, 6, 7, 8, 9, None, None, 12, None, None, 15]
|
||||
// 二分木の連結リスト表現:
|
||||
// /——— 15
|
||||
// /——— 7
|
||||
// /——— 3
|
||||
// | \——— 6
|
||||
// | \——— 12
|
||||
// ——— 1
|
||||
// \——— 2
|
||||
// | /——— 9
|
||||
// \——— 4
|
||||
// \——— 8
|
||||
|
||||
/* リストを二分木にデシリアライズする: 再帰 */
|
||||
TreeNode *arrayToTreeDFS(int *arr, int size, int i) {
|
||||
if (i < 0 || i >= size || arr[i] == INT_MAX) {
|
||||
return NULL;
|
||||
}
|
||||
TreeNode *root = (TreeNode *)malloc(sizeof(TreeNode));
|
||||
root->val = arr[i];
|
||||
root->left = arrayToTreeDFS(arr, size, 2 * i + 1);
|
||||
root->right = arrayToTreeDFS(arr, size, 2 * i + 2);
|
||||
return root;
|
||||
}
|
||||
|
||||
/* リストを二分木にデシリアライズする */
|
||||
TreeNode *arrayToTree(int *arr, int size) {
|
||||
return arrayToTreeDFS(arr, size, 0);
|
||||
}
|
||||
|
||||
/* 二分木をリストにシリアライズする: 再帰 */
|
||||
void treeToArrayDFS(TreeNode *root, int i, int *res, int *size) {
|
||||
if (root == NULL) {
|
||||
return;
|
||||
}
|
||||
while (i >= *size) {
|
||||
res = realloc(res, (*size + 1) * sizeof(int));
|
||||
res[*size] = INT_MAX;
|
||||
(*size)++;
|
||||
}
|
||||
res[i] = root->val;
|
||||
treeToArrayDFS(root->left, 2 * i + 1, res, size);
|
||||
treeToArrayDFS(root->right, 2 * i + 2, res, size);
|
||||
}
|
||||
|
||||
/* 二分木をリストにシリアライズする */
|
||||
int *treeToArray(TreeNode *root, int *size) {
|
||||
*size = 0;
|
||||
int *res = NULL;
|
||||
treeToArrayDFS(root, 0, res, size);
|
||||
return res;
|
||||
}
|
||||
|
||||
/* 二分木のメモリを解放する */
|
||||
void freeMemoryTree(TreeNode *root) {
|
||||
if (root == NULL)
|
||||
return;
|
||||
freeMemoryTree(root->left);
|
||||
freeMemoryTree(root->right);
|
||||
free(root);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TREE_NODE_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,259 @@
|
||||
/**
|
||||
* File: vector.h
|
||||
* Created Time: 2023-07-13
|
||||
* Author: Zuoxun (845242523@qq.com)、Gonglja (glj0@outlook.com)
|
||||
*/
|
||||
|
||||
#ifndef VECTOR_H
|
||||
#define VECTOR_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* ベクタ型を定義 */
|
||||
typedef struct vector {
|
||||
int size; // 現在のベクタのサイズ
|
||||
int capacity; // 現在のベクタの容量
|
||||
int depth; // 現在のベクタの深さ
|
||||
void **data; // データを指すポインタ配列
|
||||
} vector;
|
||||
|
||||
/* ベクタを構築 */
|
||||
vector *newVector() {
|
||||
vector *v = malloc(sizeof(vector));
|
||||
v->size = 0;
|
||||
v->capacity = 4;
|
||||
v->depth = 1;
|
||||
v->data = malloc(v->capacity * sizeof(void *));
|
||||
return v;
|
||||
}
|
||||
|
||||
/* ベクタを構築し、サイズと要素のデフォルト値を指定する */
|
||||
vector *_newVector(int size, void *elem, int elemSize) {
|
||||
vector *v = malloc(sizeof(vector));
|
||||
v->size = size;
|
||||
v->capacity = size;
|
||||
v->depth = 1;
|
||||
v->data = malloc(v->capacity * sizeof(void *));
|
||||
for (int i = 0; i < size; i++) {
|
||||
void *tmp = malloc(sizeof(char) * elemSize);
|
||||
memcpy(tmp, elem, elemSize);
|
||||
v->data[i] = tmp;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
/* ベクタを破棄 */
|
||||
void delVector(vector *v) {
|
||||
if (v) {
|
||||
if (v->depth == 0) {
|
||||
return;
|
||||
} else if (v->depth == 1) {
|
||||
for (int i = 0; i < v->size; i++) {
|
||||
free(v->data[i]);
|
||||
}
|
||||
free(v);
|
||||
} else {
|
||||
for (int i = 0; i < v->size; i++) {
|
||||
delVector(v->data[i]);
|
||||
}
|
||||
v->depth--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 要素をベクタの末尾に追加する(コピー方式) */
|
||||
void vectorPushback(vector *v, void *elem, int elemSize) {
|
||||
if (v->size == v->capacity) {
|
||||
v->capacity *= 2;
|
||||
v->data = realloc(v->data, v->capacity * sizeof(void *));
|
||||
}
|
||||
void *tmp = malloc(sizeof(char) * elemSize);
|
||||
memcpy(tmp, elem, elemSize);
|
||||
v->data[v->size++] = tmp;
|
||||
}
|
||||
|
||||
/* ベクタの末尾から要素を取り出す */
|
||||
void vectorPopback(vector *v) {
|
||||
if (v->size != 0) {
|
||||
free(v->data[v->size - 1]);
|
||||
v->size--;
|
||||
}
|
||||
}
|
||||
|
||||
/* ベクタをクリア */
|
||||
void vectorClear(vector *v) {
|
||||
delVector(v);
|
||||
v->size = 0;
|
||||
v->capacity = 4;
|
||||
v->depth = 1;
|
||||
v->data = malloc(v->capacity * sizeof(void *));
|
||||
}
|
||||
|
||||
/* ベクタのサイズを取得する */
|
||||
int vectorSize(vector *v) {
|
||||
return v->size;
|
||||
}
|
||||
|
||||
/* ベクタの末尾要素を取得する */
|
||||
void *vectorBack(vector *v) {
|
||||
int n = v->size;
|
||||
return n > 0 ? v->data[n - 1] : NULL;
|
||||
}
|
||||
|
||||
/* ベクタの先頭要素を取得する */
|
||||
void *vectorFront(vector *v) {
|
||||
return v->size > 0 ? v->data[0] : NULL;
|
||||
}
|
||||
|
||||
/* ベクタの添字 `pos` の要素を取得する */
|
||||
void *vectorAt(vector *v, int pos) {
|
||||
if (pos < 0 || pos >= v->size) {
|
||||
printf("vectorAt: out of range\n");
|
||||
return NULL;
|
||||
}
|
||||
return v->data[pos];
|
||||
}
|
||||
|
||||
/* ベクタの添字 `pos` の要素を設定する */
|
||||
void vectorSet(vector *v, int pos, void *elem, int elemSize) {
|
||||
if (pos < 0 || pos >= v->size) {
|
||||
printf("vectorSet: out of range\n");
|
||||
return;
|
||||
}
|
||||
free(v->data[pos]);
|
||||
void *tmp = malloc(sizeof(char) * elemSize);
|
||||
memcpy(tmp, elem, elemSize);
|
||||
v->data[pos] = tmp;
|
||||
}
|
||||
|
||||
/* ベクトルを拡張する */
|
||||
void vectorExpand(vector *v) {
|
||||
v->capacity *= 2;
|
||||
v->data = realloc(v->data, v->capacity * sizeof(void *));
|
||||
}
|
||||
|
||||
/* ベクトルを縮小する */
|
||||
void vectorShrink(vector *v) {
|
||||
v->capacity /= 2;
|
||||
v->data = realloc(v->data, v->capacity * sizeof(void *));
|
||||
}
|
||||
|
||||
/* ベクタの添字 pos に要素を挿入 */
|
||||
void vectorInsert(vector *v, int pos, void *elem, int elemSize) {
|
||||
if (v->size == v->capacity) {
|
||||
vectorExpand(v);
|
||||
}
|
||||
for (int j = v->size; j > pos; j--) {
|
||||
v->data[j] = v->data[j - 1];
|
||||
}
|
||||
void *tmp = malloc(sizeof(char) * elemSize);
|
||||
memcpy(tmp, elem, elemSize);
|
||||
v->data[pos] = tmp;
|
||||
v->size++;
|
||||
}
|
||||
|
||||
/* ベクトルの添字 pos の要素を削除する */
|
||||
void vectorErase(vector *v, int pos) {
|
||||
if (v->size != 0) {
|
||||
free(v->data[pos]);
|
||||
for (int j = pos; j < v->size - 1; j++) {
|
||||
v->data[j] = v->data[j + 1];
|
||||
}
|
||||
v->size--;
|
||||
}
|
||||
}
|
||||
|
||||
/* ベクトルの要素を交換する */
|
||||
void vectorSwap(vector *v, int i, int j) {
|
||||
void *tmp = v->data[i];
|
||||
v->data[i] = v->data[j];
|
||||
v->data[j] = tmp;
|
||||
}
|
||||
|
||||
/* ベクトルが空かどうか */
|
||||
bool vectorEmpty(vector *v) {
|
||||
return v->size == 0;
|
||||
}
|
||||
|
||||
/* ベクトルが満杯かどうか */
|
||||
bool vectorFull(vector *v) {
|
||||
return v->size == v->capacity;
|
||||
}
|
||||
|
||||
/* ベクトルが等しいかどうか */
|
||||
bool vectorEqual(vector *v1, vector *v2) {
|
||||
if (v1->size != v2->size) {
|
||||
printf("size not equal\n");
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < v1->size; i++) {
|
||||
void *a = v1->data[i];
|
||||
void *b = v2->data[i];
|
||||
if (memcmp(a, b, sizeof(a)) != 0) {
|
||||
printf("data %d not equal\n", i);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ベクタ内部をソート */
|
||||
void vectorSort(vector *v, int (*cmp)(const void *, const void *)) {
|
||||
qsort(v->data, v->size, sizeof(void *), cmp);
|
||||
}
|
||||
|
||||
/* 出力関数。出力対象の変数を表示する関数を渡す必要がある */
|
||||
/* 現在は深さ 1 の vector のみ出力をサポート */
|
||||
void printVector(vector *v, void (*printFunc)(vector *v, void *p)) {
|
||||
if (v) {
|
||||
if (v->depth == 0) {
|
||||
return;
|
||||
} else if (v->depth == 1) {
|
||||
if(v->size == 0) {
|
||||
printf("\n");
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < v->size; i++) {
|
||||
if (i == 0) {
|
||||
printf("[");
|
||||
} else if (i == v->size - 1) {
|
||||
printFunc(v, v->data[i]);
|
||||
printf("]\r\n");
|
||||
break;
|
||||
}
|
||||
printFunc(v, v->data[i]);
|
||||
printf(",");
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < v->size; i++) {
|
||||
printVector(v->data[i], printFunc);
|
||||
}
|
||||
v->depth--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 現在は深さ 2 の vector のみ出力をサポート */
|
||||
void printVectorMatrix(vector *vv, void (*printFunc)(vector *v, void *p)) {
|
||||
printf("[\n");
|
||||
for (int i = 0; i < vv->size; i++) {
|
||||
vector *v = (vector *)vv->data[i];
|
||||
printf(" [");
|
||||
for (int j = 0; j < v->size; j++) {
|
||||
printFunc(v, v->data[j]);
|
||||
if (j != v->size - 1)
|
||||
printf(",");
|
||||
}
|
||||
printf("],");
|
||||
printf("\n");
|
||||
}
|
||||
printf("]\n");
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // VECTOR_H
|
||||
@@ -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