双向链表 2 个值 c++
我需要用 C++ 为学校制作一个扑克游戏。 我制作了一个班级卡片和甲板。 我需要制作一个所有卡片的双向链接列表,每张卡片都有一个花色和一个等级(值)。如何将 2 个属性(花色和等级)附加到双向链表中的卡上。
I need to make a poker game for school in c++.
I have made a class Card and Deck.
I need to make a doubly linked list of all the cards, and every card has a suit and a rank (value). How can I attach 2 attributes (suit and rank) to a Card in a doubly linked list.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
双链表是一种具有指向上一个和下一个链接的指针的结构(结构或类)。除了这些指针之外,您还可以添加任意数据,这些数据可以被视为有效负载。您可以在那里放置任何您想要的数据。这是一个例子:
A double linked list is a structure (a struct or a class) with pointers to the previous and the next link. In addition to these pointers you can add arbitrary data, which can be considered the payload. There you can put any data you want. Here is an example:
花色和等级是卡牌的属性,与链表无关。因此,这些属性最好封装到 Card 类中。
如果您已经这样做了,但仍有不清楚的地方,请扩展您的问题。
The suit and the rank are properties of the card, and have nothing to do with the linked list. As such, these properties are best encapsulated into the
Card
class.If you already do this, and something remains unclear, please expand your question.