Results 1 to 5 of 5
  1. #1

    Default [C++] HELP. trying to create a binary tree structure. crash when adding nodes.


    Code:
    struct TreeNode {
           int item;     // The data in this node.
           TreeNode *left;  // Pointer to the left subtree.
           TreeNode *right; // Pointer to the right subtree.
    };
    int main (void){
    	TreeNode myTree;
    	myTree.item = 1;
    	myTree.left->item = 2;
    	myTree.right->item = 3; //it starts crashing here. 
    	myTree.left->left->item = 4;
    	myTree.left->right->item = 5;
    	myTree.right->left->item = 6;
    	myTree.right->right->item = 7;
    	return 0;
    }
    it compiles fine, and i think the syntax is fine. but it crashes when i run it. i removed the lines starting at item = 3, and it will run fine.

  2. #2

    Default Re: [C++] HELP. trying to create a binary tree structure. crash when adding nodes.

    Kanang imong TreeNode *left ug *right unsa ang reference type iyang gi-point ana?

  3. #3

    Default Re: [C++] HELP. trying to create a binary tree structure. crash when adding nodes.

    referencing another TreeNode. Solved na, i have to initialize what the pointers are pointing at. Never did understand how to handle referencing in C/C++.. hehe.
    thanks bro.

  4. #4

    Default Re: [C++] HELP. trying to create a binary tree structure. crash when adding node

    You're welcome.

    OT : Why naggamit ka ug struct in C++? Para nako it should be better use the class statement because it is more powerful and OOP than struct.

  5. #5

    Default Re: [C++] HELP. trying to create a binary tree structure. crash when adding nodes.

    assignment na sa ako uyab gd. hehe. di pd kaau ko khbw ug C++.. hehe. struct ra man iya n-hibawan ug gamit..

  6.    Advertisement

Similar Threads

 
  1. Need Help -- trying to find this establishment (NS Enterprise)
    By kamikaze_007 in forum General Discussions
    Replies: 13
    Last Post: 05-01-2012, 01:35 AM
  2. need help :) trying to make, build own pc
    By monchsolstice in forum Computer Hardware
    Replies: 13
    Last Post: 04-07-2011, 12:31 PM
  3. Replies: 33
    Last Post: 02-19-2009, 02:38 AM
  4. Help My BF's Ex- Is Trying to Get Back With Him!
    By mary_HRD_VFI in forum "Love is..."
    Replies: 32
    Last Post: 05-03-2008, 03:10 AM
  5. Replies: 9
    Last Post: 02-03-2008, 02:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top