Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #ifndef CARDS_HH
  2. #define CARDS_HH
  3.  
  4. #include <iostream>
  5. #include <memory>
  6.  
  7. class Cards {
  8.  
  9. public:
  10. // A dynamic structure must have a constructor that initializes
  11. // the top elem as nullptr.
  12. Cards();
  13.  
  14. // Adds a new card with the given id as the topmost element.
  15. void add(int id);
  16.  
  17. // Prints the content of the data structure with ordinal numbers to the
  18. // output stream given as a parameter starting from the first element.
  19. void print(std::ostream& s);
  20.  
  21. // Removes the topmost card and returns it as reference parameter number.
  22. // Returns false, if the data structure is empty, otherwise returns true.
  23. bool remove(int& id);
  24.  
  25. // Reverses the content of the data structure as opposite.
  26. void reverse();
  27.  
  28. private:
  29. struct Card_data {
  30. int data;
  31. std::shared_ptr<Card_data> next;
  32. };
  33.  
  34. std::shared_ptr<Card_data> top_;
  35. std::shared_ptr<Card_data> bottom_;
  36. };
  37.  
  38. #endif // CARDS_HH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement