帮忙把下面使用的STL操作改为自己定义的(因为不能使用STL)
#include <iostream>#include <string>#include <vector>#include <random>enum class Suit { SPADE, HEART, CLUB, DIAMOND};enum class Rank { ACE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING};class Card {public: Card(Suit suit, Rank rank) : suit(suit), rank(rank) {} Suit getSuit() const { return suit; } Rank getRank() const { return rank; } friend std::ostream& operator<<(std::ostream& os, const Card& card) { std::string suitStr; std::string rankStr; switch (static_cast<int>(card.suit)) { case 0: suitStr = "♠"; break; case 1: suitStr = "♥"; break; case 2: suitStr = "♣"; break; case 3: suitStr = "♦"; break; } switch (static_cast<int>(card.rank)) { case 0: rankStr = "A"; break; case 1: rankStr = "2"; break; case 2: rankStr = "3"; break; case 3: rankStr = "4"; break; case 4: rankStr = "5"; break; case 5: rankStr = "6"; break; case 6: rankStr = "7"; break; case 7: rankStr = "8"; break; case 8: rankStr = "9"; break; case 9: rankStr = "10"; break; case 10: rankStr = "J"; break; case 11: rankStr = "Q"; break; case 12: rankStr = "K"; break; } os << suitStr << rankStr; return os; }private: Suit suit; Rank rank;};template<typename T>class List {public: void add(const T& item) { items.push_back(item); } T get(int index) const { return items[index]; } int getSize() const { return items.size(); }private: std::vector<T> items;};template<typename T>class Player {public: void addCard(const T& card) { hand.add(card); } void showHand() const { for (int i = 0; i < hand.getSize(); i++) { std::cout << hand.get(i) << " "; } std::cout << std::endl; } void playCard(int index, List<T>& pile) { T card = hand.get(index); pile.add(card); hand.remove(index); }private: List<T> hand;};void playCardGame() { List<Card> deck; // 扑克牌列表 // 生成扑克牌 for (int suit = static_cast<int>(Suit::SPADE); suit <= static_cast<int>(Suit::DIAMOND); suit++) { for (int rank = static_cast<int>(Rank::ACE); rank <= static_cast<int>(Rank::KING); rank++) { Card card(static_cast<Suit>(suit), static_cast<Rank>(rank)); deck.add(card); } } // 打乱扑克牌顺序 std::random_device rd; std::mt19937 gen(rd()); std::shuffle(deck.begin(), deck.end(), gen); // 展示扑克牌 std::cout << "展示扑克牌:" << std::endl; for (int i = 0; i < deck.getSize(); i++) { std::cout << deck.get(i) << " "; } std::cout << std::endl; // 发牌给三位玩家 Player<Card> player1, player2, player3; for (int i = 0; i < deck.getSize(); i++) { if (i % 3 == 0) { player1.addCard(deck.get(i)); } else if (i % 3 == 1) { player2.addCard(deck.get(i)); } else { player3.addCard(deck.get(i)); } } // 展示玩家手中的扑克牌 std::cout << "玩家1手中的扑克牌:"; player1.showHand(); std::cout << "玩家2手中的扑克牌:"; player2.showHand(); std::cout << "玩家3手中的扑克牌:"; player3.showHand(); // 玩家1出牌 List<Card> pile; // 牌堆 std::cout << "玩家1出牌:" << std::endl; player1.playCard(0, pile); // 展示玩家手中的扑克牌和牌堆中的扑克牌 std::cout << "玩家1手中的扑克牌:"; player1.showHand(); std::cout << "牌堆中的扑克牌:"; for (int i = 0; i < pile.getSize(); i++) { std::cout << pile.get(i) << " "; } std::cout << std::endl;}int main() { playCardGame(); return 0;}