如何在速推中为节点分配标签
How to assign labels to nodes in boost?
我知道图的节点数。我想将图的节点分配标签为 A,B,C,D。如果我有 5 个节点,请将其标记为 A,B,C,D,E。如果我有 6 个节点,请将其标记为 A,B,C,D,E,F。您能为此建议任何动态方法吗?
enum nodes { A, B, C, D, E };
char name[] = "ABCDE";
你的问题根本不清楚 - 我不明白你为什么需要提升或你想做什么。也就是说,让我们假设:
-
您有
enum
节点类型A
..Z
. -
您需要一种方法在运行时将枚举值转换为字符串表示形式。
gcc.godbolt.org 例子。
#include <cstddef>
// Use `enum class` for additional safety.
// Explictly specify the underyling type as we're going to use the
// enum values to access an array.
enum class nodes : std::size_t { A = 0, B, C, D, E, /* ... */ };
// `constexpr` allows this function to work both at run-time and
// compile-time.
constexpr auto get_char_for(nodes n) noexcept
{
// Represent the alphabet as a `constexpr` C-style string.
constexpr const char* letters = "ABCDEFGHIJKLMNOPQRSTUWXYZ";
// Access and return the alphabet letter at position `n`.
return letters[static_cast<std::size_t>(n)];
}
static_assert(get_char_for(nodes::A) == 'A');
相关文章:
- 预分配的节点向量中的无锁树节点分配
- 如何在 C++11 的内存池中分配 std::map 的内部RB_tree节点?
- nullptr = 节点分配不正确
- C++错误(从不兼容的类型"void"分配给树节点*)
- 根节点应具有分配的节点,但仍为 NULL。为什么我无法将节点分配给根?
- 将节点添加到链接列表中,而无需明确分配内存空间(无需使用新)
- 是否可以将新的列表节点分配给链表的现有节点
- 在声明节点创建链接列表时,为什么静态内存分配不起作用
- 将指针分配给链接列表节点会引发"Segmentation Fault"
- 如何从链表上的节点为分配的类释放内存
- 如何在速推中为节点分配标签
- 用C++在树中分配节点指针
- 关于在omnetpp.ini中将两个不同的应用程序随机分配到50个节点
- 分段 C++中链表节点分配的错误
- 我们需要为链表节点分配内存吗
- 为节点分配指针地址
- 将子节点分配给父节点
- 在C/ c++中,链表只有头指针分配在堆栈中,其他节点分配在堆中.这可能导致内存泄漏
- 为链表中的节点分配内存,但出乎意料的是,它内部的下一个节点也被分配了
- 使用pugixml将节点分配给新的父节点