Guest User

Untitled

a guest
Jan 21st, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. Struct node{
  2. node leftChild;
  3. node rightChild;
  4. int data;}
  5.  
  6. foo (node head)
  7. {
  8. std::cout << head.leftChild.data;
  9. }
  10.  
  11. /* This is a problem because of the recursive nature of the structure. leftChild also
  12. contains a leftChild itself, which also contains a leftChild, etc. forever. */
  13. struct node
  14. {
  15. node leftChild; // how big is leftChild? infinitely large!
  16. node rightChild; // how big is rightChild? infinitely large!
  17. int data;
  18. }
  19.  
  20. /* This is not a problem because the size of a pointer is always 4 bytes (assuming 32-
  21. bit system). You can allocate room for the child nodes without recursively requiring an
  22. infinite amount of memory. */
  23. struct node
  24. {
  25. node* leftChild; // how big is leftChild? 4 bytes (assuming 32-bit system)
  26. node* rightChild; // how big is rightChild? 4 bytes (assuming 32-bit system)
  27. int data;
  28. }
  29.  
  30. void foo(node head)
  31. {
  32. std::cout << head.leftChild->data; // assuming leftChild points to a valid object!
  33. }
Add Comment
Please, Sign In to add comment