枚举可以是 class 吗? - C++ [枚举 class] [理论]
Can an enumeration be a class? - C++ [enum class] [Theory]
我的最终目标:
从头开始创建哈希-table 的实现。扭曲,如果哈希桶中的条目数大于 10,则它存储在二叉搜索树中,否则存储在链表中。
据我所知,实现这一目标的唯一方法是通过
enum class type_name { a, b };
我的问题: 'a' 和 'b' 可以 class 吗?
思考过程:
因此,为了实现散列 table,我正在考虑以这种方式制作枚举 class 的数组,一旦 Linked List 位于数组的任何索引都将替换为 二叉搜索树.
如果这不可能,实现它的最佳方法是什么?我对链表和二叉搜索树的实现已经完成并且运行良好。
注意:我不是在寻找完整的实现/完整代码。我希望能够自己编写代码,但我认为我的理论有缺陷。
我的想法的可视化
----------------------------------H A S H T A B L E---------------------------------------
enum class Hash { LinkedList, Tree };
INDEXES: 0 1 2 3 4
Hash eg = new Hash [ LinkedList, LinkedList, LinkedList, LinkedList, LinkedList ]
//11th element is inserted into eg[2]
//Method to Replace Linked List with Binary Search Tree
if (eg[1].getSize() > 10) {
Tree toReplace();
Node *follow = eg[1].headptr; //Each linked list is made of connected
//headptr is a pointer to the first element of the linked list
while ( follow != nullptr ){
toReplace.insert(follow->value);
follow = follow.next() //Next is the pointer to the next element in the linked list
}
}
//Now, the Linked List at eg[2] is replaced with a Binary Search Tree
Hash eg = new Hash [ LinkedList, LinkedList, Tree, LinkedList, LinkedList ]
简答:否
An enumeration is a distinct type whose value is restricted to a range
of values (see below for details), which may include several
explicitly named constants ("enumerators"). The values of the
constants are values of an integral type known as the underlying type
of the enumeration.
http://en.cppreference.com/w/cpp/language/enum
类 不会是 'values of an integral type'。
您也许可以通过 tuple
.
实现您想要的效果
我的最终目标:
从头开始创建哈希-table 的实现。扭曲,如果哈希桶中的条目数大于 10,则它存储在二叉搜索树中,否则存储在链表中。
据我所知,实现这一目标的唯一方法是通过
enum class type_name { a, b };
我的问题: 'a' 和 'b' 可以 class 吗?
思考过程:
因此,为了实现散列 table,我正在考虑以这种方式制作枚举 class 的数组,一旦 Linked List 位于数组的任何索引都将替换为 二叉搜索树.
如果这不可能,实现它的最佳方法是什么?我对链表和二叉搜索树的实现已经完成并且运行良好。
注意:我不是在寻找完整的实现/完整代码。我希望能够自己编写代码,但我认为我的理论有缺陷。
我的想法的可视化
----------------------------------H A S H T A B L E---------------------------------------
enum class Hash { LinkedList, Tree };
INDEXES: 0 1 2 3 4
Hash eg = new Hash [ LinkedList, LinkedList, LinkedList, LinkedList, LinkedList ]
//11th element is inserted into eg[2]
//Method to Replace Linked List with Binary Search Tree
if (eg[1].getSize() > 10) {
Tree toReplace();
Node *follow = eg[1].headptr; //Each linked list is made of connected
//headptr is a pointer to the first element of the linked list
while ( follow != nullptr ){
toReplace.insert(follow->value);
follow = follow.next() //Next is the pointer to the next element in the linked list
}
}
//Now, the Linked List at eg[2] is replaced with a Binary Search Tree
Hash eg = new Hash [ LinkedList, LinkedList, Tree, LinkedList, LinkedList ]
简答:否
An enumeration is a distinct type whose value is restricted to a range of values (see below for details), which may include several explicitly named constants ("enumerators"). The values of the constants are values of an integral type known as the underlying type of the enumeration.
http://en.cppreference.com/w/cpp/language/enum
类 不会是 'values of an integral type'。
您也许可以通过 tuple
.