My program is binary serach tree...
how can i modify it so i can avoid file permission problems..
using ubuntu 12.10
Printable View
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);
}
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?
@salem
Thanks for inlining it sir:)
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) {}