Card Deck Class

sdaouk
sdaouk used Ask the Experts™
on
Implementing a cardDeck class using a vector of Card* and would like some help implementing a sort and shuffle methods. Using an enum for the suits and integers for the ranks of each card

problem url: http://www.csd.uwo.ca/courses/CS307a/assign3.html
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
try making a swap function:

void CardDeck::swap(size_t pos1, size_t pos2) {
   const Card* tempcard = this->at(pos1);
   this->at(pos1) = this->at(pos2);
   this->at(pos2) = tempcard;
 }

and call it a random number of times from the shuffle method:

void CardDeck::shuffle() {
 for(size_t random = 0; random < rand()%size()*10; random++) {
  swap(rand()%size(), rand()%size());
}


sort is a little trickier, but if you're using a vector of cards, then there is a sort algorithm already defined if you include <algorithm>.
 

Commented:
This question didn't show any activity for more than 21 days. I will ask Community Support to close it unless you finalize it yourself within 7 days.
You can always request to keep this question open. But remember, experts can only help if you provide feedback to their comments.
Unless there is objection or further activity,  I will suggest to accept

    "__fork__"

comment(s) as an answer.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
========
Werner
Force accepted

** Mindphaser - Community Support Moderator **

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial