home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 May / VPR9705A.ISO / VPR_DATA / PROGRAM / CBTRIAL / SETUP / DATA.Z / DEQUE.CPP < prev    next >
C/C++ Source or Header  |  1997-02-14  |  992b  |  51 lines

  1.  #include <deque>
  2.  #include <string>
  3.  
  4.  using namespace std;
  5.  
  6.  deque<string> deck_of_cards;
  7.  deque<string> current_hand;
  8.  
  9.  void initialize_cards(deque<string>& cards)
  10.  {
  11.    cards.push_front("aceofspades");
  12.    cards.push_front("kingofspades");
  13.    cards.push_front("queenofspades");
  14.    cards.push_front("jackofspades");
  15.    cards.push_front("tenofspades");
  16.    //
  17.    // etc.
  18.    //
  19.  }
  20.  
  21.  template <class It, class It2>
  22.  void print_current_hand(It start, It2 end)
  23.  {
  24.    while (start < end)
  25.      cout << *start++ << endl;
  26.  }
  27.  
  28.  
  29.  template <class It, class It2>
  30.  void deal_cards(It, It2 end)
  31.  {
  32.    for (int i=0;i<5;i++)
  33.    {
  34.      current_hand.insert(current_hand.begin(),*end);
  35.      deck_of_cards.erase(end++);
  36.    }
  37.  }
  38.  
  39.  void play_poker()
  40.  {
  41.    initialize_cards(deck_of_cards);
  42.    deal_cards(current_hand.begin(),deck_of_cards.begin());
  43.  }
  44.  
  45.  int main ()
  46.  {
  47.    play_poker();
  48.    print_current_hand(current_hand.begin(),current_hand.end());
  49.    return 0;
  50.  }
  51.