fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. using namespace std;
  6.  
  7. //---------------------------------------------------------------------------
  8. // node<T> class:
  9. // --
  10. //
  11. // Assumptions:
  12. // -- <T> maintains it's own comparable functionality
  13. //---------------------------------------------------------------------------
  14.  
  15. template <typename T>
  16. class node {
  17.  
  18. public:
  19. node(T value); //constructor
  20. node(const node<T>&); //copy constructor
  21. void setFrequency(int); //sets the frequency
  22. int getFrequency(); //returns the frequency
  23. T getItem(); //returns the item
  24.  
  25. private:
  26. T item;
  27. int frequency;
  28. node<T>* leftChild;
  29. node<T>* rightChild;
  30. bool leftChildThread;
  31. bool rightChildThread;
  32. };
  33.  
  34. //-------------------------- Constructor ------------------------------------
  35. template <typename T>
  36. node<T>::node(T value) {
  37. item = value;
  38. frequency = 1;
  39.  
  40. }
  41.  
  42. //-------------------------- Copy ------------------------------------
  43. template <typename T>
  44. node<T>::node(const node<T>& copyThis) {
  45. item = copyThis.value;
  46. frequency = copyThis.frequency;
  47. }
  48.  
  49. //-------------------------- setFrequency ------------------------------------
  50. template <typename T>
  51. void node<T>::setFrequency(int num) {
  52. frequency = num;
  53. }
  54.  
  55. //-------------------------- getFrequency ------------------------------------
  56. template <typename T>
  57. int node<T>::getFrequency() {
  58. return frequency;
  59. }
  60.  
  61. //-------------------------- getItem ------------------------------------
  62. template <typename T>
  63. T node<T>::getItem() {
  64. return item;
  65. }
  66.  
  67. int main() {
  68. node<int> n (33);
  69. int x = n.getItem();
  70. cout << x << endl;
  71. return 0;
  72. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
33