Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Struct node{
- node leftChild;
- node rightChild;
- int data;}
- foo (node head)
- {
- std::cout << head.leftChild.data;
- }
- /* This is a problem because of the recursive nature of the structure. leftChild also
- contains a leftChild itself, which also contains a leftChild, etc. forever. */
- struct node
- {
- node leftChild; // how big is leftChild? infinitely large!
- node rightChild; // how big is rightChild? infinitely large!
- int data;
- }
- /* This is not a problem because the size of a pointer is always 4 bytes (assuming 32-
- bit system). You can allocate room for the child nodes without recursively requiring an
- infinite amount of memory. */
- struct node
- {
- node* leftChild; // how big is leftChild? 4 bytes (assuming 32-bit system)
- node* rightChild; // how big is rightChild? 4 bytes (assuming 32-bit system)
- int data;
- }
- void foo(node head)
- {
- std::cout << head.leftChild->data; // assuming leftChild points to a valid object!
- }
Add Comment
Please, Sign In to add comment