My program is binary serach tree...
how can i modify it so i can avoid file permission problems..
using ubuntu 12.10
My program is binary serach tree...
how can i modify it so i can avoid file permission problems..
using ubuntu 12.10
Inlined
Code:#include<iostream> #include<string> using namespace std; class node { private: int data; node *left; node *right; public: node(int d) { data=d; cout<<data<<endl; left=NULL; right=NULL; } friend class list; }; class list { public: node *root; void insert(int data) { if(root==NULL) { root=new node(data); } else if(data>root->data) { insert(root->right,data); } else if(data<root->data) { insert(root->left,data); } } void insert(node *nd,int data) { if(nd==NULL) { nd=new node(data); } else if(data>nd->data) { insert(nd->right,data); } else if(data<nd->data) { insert(nd->left,data); } } }; int main() { list l; l.insert(9); l.insert(6); }
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
No need. There is nothing in that source file which does anything that would cause file permission problems.
If you are encountering such problems, it is specific to your environment, and has nothing to do with C++ programming. You'll therefore need to work out the answer for yourself.
> if(root==NULL)
Do you have a constructor, which initialised root to NULL?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
@salem
Thanks for inlining it sir
Last edited by thriller500; 11-07-2012 at 04:18 AM.
since you're using ubuntu 12.10, you have gcc 4.6, so you can add compiler option -std=c++0x, and use the nullptr keyword in place of NULL. I highly recommend this.
Better yet, learn about constructor initialisation lists:Code:list() : root(NULL) {}
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"