You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hello-algo/en/codes/cpp/utils/vertex.hpp

37 lines
697 B

/**
* File: vertex.hpp
* Created Time: 2023-03-02
* Author: krahets (krahets@163.com)
*/
#pragma once
#include <vector>
using namespace std;
/* Vertex class */
struct Vertex {
int val;
Vertex(int x) : val(x) {
}
};
/* Input a list of values vals, return a list of vertices vets */
vector<Vertex *> valsToVets(vector<int> vals) {
vector<Vertex *> vets;
for (int val : vals) {
vets.push_back(new Vertex(val));
}
return vets;
}
/* Input a list of vertices vets, return a list of values vals */
vector<int> vetsToVals(vector<Vertex *> vets) {
vector<int> vals;
for (Vertex *vet : vets) {
vals.push_back(vet->val);
}
return vals;
}