fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <typename T> class RedBlackNode{
  5. protected:
  6. union RedBlackPointer{
  7. RedBlackPointer() : node(0) { } // <==== default constructor
  8. RedBlackNode *node;
  9. struct{
  10. unsigned value:1; // for color / other info
  11. }flag;
  12. }left, right, parent;
  13. T key;
  14. public:
  15. void initialize(T key, RedBlackPointer left = RedBlackPointer(), //refer to default ctor
  16. RedBlackPointer right = RedBlackPointer(),
  17. RedBlackPointer parent = RedBlackPointer()){
  18. this->key = key;
  19. this->left = left; this->right = right;
  20. this->parent = parent;
  21. }
  22. void show() {
  23. cout<<left.node<<","<<right.node<<","<<parent.node<<","<<key<<endl;
  24. }
  25. };
  26.  
  27. int main() {
  28. RedBlackNode<int> N;
  29. N.initialize(5);
  30. N.show();
  31. // your code goes here
  32. return 0;
  33. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
0,0,0,5