mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-27 21:06:29 +08:00
37 lines
673 B
C++
37 lines
673 B
C++
|
/**
|
||
|
* File: vertex.hpp
|
||
|
* Created Time: 2023-03-02
|
||
|
* Author: krahets (krahets@163.com)
|
||
|
*/
|
||
|
|
||
|
#pragma once
|
||
|
|
||
|
#include <vector>
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
/* 頂點類別 */
|
||
|
struct Vertex {
|
||
|
int val;
|
||
|
Vertex(int x) : val(x) {
|
||
|
}
|
||
|
};
|
||
|
|
||
|
/* 輸入值串列 vals ,返回頂點串列 vets */
|
||
|
vector<Vertex *> valsToVets(vector<int> vals) {
|
||
|
vector<Vertex *> vets;
|
||
|
for (int val : vals) {
|
||
|
vets.push_back(new Vertex(val));
|
||
|
}
|
||
|
return vets;
|
||
|
}
|
||
|
|
||
|
/* 輸入頂點串列 vets ,返回值串列 vals */
|
||
|
vector<int> vetsToVals(vector<Vertex *> vets) {
|
||
|
vector<int> vals;
|
||
|
for (Vertex *vet : vets) {
|
||
|
vals.push_back(vet->val);
|
||
|
}
|
||
|
return vals;
|
||
|
}
|