neilabak
شنبه 18 اسفند 1386, 10:17 صبح
سلام.من این برنامه رو کامل نوشتم ولی وقتی براش mainمینویسم error میده سعی کردم رفعش کنم ولی وقتی اونو رفع میکنم جاهای دیگش error میده.لطفا اگه کسی میتونه اشکالشو رفع کنه .
#include <iostream.h>
class threadnode{
friend class threadtree;
public:
/* threadnode(bool lth,threadnode * lch,int dat ,threadnode * rch,bool rth)
{lthread=lth;
lchild=lch;
data=dat;
rchild=rch;
rthread=rth;
}
threadnode(char ch) { data = ch;};
threadnode(threadnode * lch,int dat ,threadnode * rch)
{lchild=lch;
data=dat;
rchild=rch;
};
*/
private:
bool lthread;
threadnode *lchild;
char data;
threadnode *rchild;
bool rthread;
};
////////////////////////////////////////////////////////////////////////
class threadtree{
public:
//void gettree();
threadtree(int th)
{
nn=th;
r=root=new threadnode[nn];}
threadnode* change(threadnode *t);
threadnode* next(threadnode *a);
threadnode* before(threadnode *a);
threadnode* InorderSucc(threadnode *current);
void InsertRight(threadnode *s, char ch);
threadnode* Inordercuss(threadnode *current);
void Insertleft(threadnode *s, char ch);
void creat();
private:
threadnode *root;
threadnode *r;
int nn;//nn=node number
};
//////////////////////////////////////////
threadnode* threadtree::next(threadnode *a)
{threadtree t(nn);
t.root=a;
threadnode *temp=a->rchild;
if(!a->rthread)
while(!temp->lthread)
temp=temp->lchild;
a=temp;
if(a==t.root)
{cout<<"tree has just one node \n";
return root;
}
else
return a;
};
//////////////////////////////////////////
threadnode* threadtree::before(threadnode *a)
{threadtree t(nn);
t.root=a;
threadnode *temp=a->lchild;
if(!a->lthread)
while(!temp->rthread)
temp=temp->rchild;
a=temp;
if(a==t.root)
{cout<<"tree has just one node \n";
return root;
}
else
return a;
};
///////////////////////////////////////////
threadnode* threadtree::InorderSucc(threadnode *current)
{
threadnode*temp = current->rchild;
if (! current->rthread)
while (! temp->lthread) temp = temp->lchild;
return temp;
};
/////////////////////////////////////////
void threadtree::InsertRight(threadnode *s, char ch)
{
threadnode *r = new threadnode;
r->data=ch;
r->rchild = s->rchild;
r->rthread = s->rthread;
r->lchild = s;
r->lthread = true;
s->rchild = r;
s->rthread = false;
if (! r->rthread) {
threadnode *temp = InorderSucc(r);
temp->lchild = r;
}
};
/////////////////////////////////////
threadnode* threadtree::Inordercuss(threadnode *current)
{
threadnode *temp = current->lchild;
if (! current->lthread)
while (! temp->rthread) temp = temp->rchild;
return temp;
};
//////////////////////////////////////
void threadtree::Insertleft(threadnode *s, char ch)
{
threadnode *r = new threadnode;
r->data=ch;
r->lchild = s->lchild;
r->lthread = s->lthread;
r->rchild = s;
r->rthread = true;
s->lchild = r;
s->lthread = false;
if (! r->lthread) {
threadnode *temp = Inordercuss(r);
temp->rchild = r;
}
};
////////////////////////////////////////////
void threadtree::creat()
{
// cout<<"entre the number of tree";
// cin>>nn;
/////////
int m=0;
char d,lch,rch;
cout<<"enter root data \n";
cin>>d;
r=root=new threadnode;
r->data=root->data=d;
// cout<<"enter date of lch and rch";
//cin>>lch>>rch;
//threadnode *r=root;
for (int i=0;i<nn;i++)
{
cout<<"enter data"<<i<<"om \n";
cin>> r[i].data;
cout<<"enter lch & rch:\n";
cin>>rch>>lch;
if(lch!=0)
{threadnode *temp=new threadnode;
temp->lchild=temp->rchild=0;
r[i].lchild=temp;
r[++m]=*temp;
}
else
r[i].lchild=0;
if(rch!=0)
{
threadnode *temp=new threadnode;
temp->lchild=temp->rchild=0;
r[i].rchild=temp;
r[++m]=*temp;
}
else
r[i].rchild=0;
}
};
threadnode* threadtree::change(threadnode *t)
{ for(int i=0;i<nn;i++)
{ if(r[i].lchild)
r[i].lthread=false ;
else
{r[i].lthread=true;
r[i].lchild=before(&r[i]);
}
}
return t;
};
//////////////////////////////////////////////////////
void main()
{threadtree t;
t.creat();
}
من تا امشب وقت دارم لطفا اگه کسی میتونه دریغ نکنه.
ممنون
#include <iostream.h>
class threadnode{
friend class threadtree;
public:
/* threadnode(bool lth,threadnode * lch,int dat ,threadnode * rch,bool rth)
{lthread=lth;
lchild=lch;
data=dat;
rchild=rch;
rthread=rth;
}
threadnode(char ch) { data = ch;};
threadnode(threadnode * lch,int dat ,threadnode * rch)
{lchild=lch;
data=dat;
rchild=rch;
};
*/
private:
bool lthread;
threadnode *lchild;
char data;
threadnode *rchild;
bool rthread;
};
////////////////////////////////////////////////////////////////////////
class threadtree{
public:
//void gettree();
threadtree(int th)
{
nn=th;
r=root=new threadnode[nn];}
threadnode* change(threadnode *t);
threadnode* next(threadnode *a);
threadnode* before(threadnode *a);
threadnode* InorderSucc(threadnode *current);
void InsertRight(threadnode *s, char ch);
threadnode* Inordercuss(threadnode *current);
void Insertleft(threadnode *s, char ch);
void creat();
private:
threadnode *root;
threadnode *r;
int nn;//nn=node number
};
//////////////////////////////////////////
threadnode* threadtree::next(threadnode *a)
{threadtree t(nn);
t.root=a;
threadnode *temp=a->rchild;
if(!a->rthread)
while(!temp->lthread)
temp=temp->lchild;
a=temp;
if(a==t.root)
{cout<<"tree has just one node \n";
return root;
}
else
return a;
};
//////////////////////////////////////////
threadnode* threadtree::before(threadnode *a)
{threadtree t(nn);
t.root=a;
threadnode *temp=a->lchild;
if(!a->lthread)
while(!temp->rthread)
temp=temp->rchild;
a=temp;
if(a==t.root)
{cout<<"tree has just one node \n";
return root;
}
else
return a;
};
///////////////////////////////////////////
threadnode* threadtree::InorderSucc(threadnode *current)
{
threadnode*temp = current->rchild;
if (! current->rthread)
while (! temp->lthread) temp = temp->lchild;
return temp;
};
/////////////////////////////////////////
void threadtree::InsertRight(threadnode *s, char ch)
{
threadnode *r = new threadnode;
r->data=ch;
r->rchild = s->rchild;
r->rthread = s->rthread;
r->lchild = s;
r->lthread = true;
s->rchild = r;
s->rthread = false;
if (! r->rthread) {
threadnode *temp = InorderSucc(r);
temp->lchild = r;
}
};
/////////////////////////////////////
threadnode* threadtree::Inordercuss(threadnode *current)
{
threadnode *temp = current->lchild;
if (! current->lthread)
while (! temp->rthread) temp = temp->rchild;
return temp;
};
//////////////////////////////////////
void threadtree::Insertleft(threadnode *s, char ch)
{
threadnode *r = new threadnode;
r->data=ch;
r->lchild = s->lchild;
r->lthread = s->lthread;
r->rchild = s;
r->rthread = true;
s->lchild = r;
s->lthread = false;
if (! r->lthread) {
threadnode *temp = Inordercuss(r);
temp->rchild = r;
}
};
////////////////////////////////////////////
void threadtree::creat()
{
// cout<<"entre the number of tree";
// cin>>nn;
/////////
int m=0;
char d,lch,rch;
cout<<"enter root data \n";
cin>>d;
r=root=new threadnode;
r->data=root->data=d;
// cout<<"enter date of lch and rch";
//cin>>lch>>rch;
//threadnode *r=root;
for (int i=0;i<nn;i++)
{
cout<<"enter data"<<i<<"om \n";
cin>> r[i].data;
cout<<"enter lch & rch:\n";
cin>>rch>>lch;
if(lch!=0)
{threadnode *temp=new threadnode;
temp->lchild=temp->rchild=0;
r[i].lchild=temp;
r[++m]=*temp;
}
else
r[i].lchild=0;
if(rch!=0)
{
threadnode *temp=new threadnode;
temp->lchild=temp->rchild=0;
r[i].rchild=temp;
r[++m]=*temp;
}
else
r[i].rchild=0;
}
};
threadnode* threadtree::change(threadnode *t)
{ for(int i=0;i<nn;i++)
{ if(r[i].lchild)
r[i].lthread=false ;
else
{r[i].lthread=true;
r[i].lchild=before(&r[i]);
}
}
return t;
};
//////////////////////////////////////////////////////
void main()
{threadtree t;
t.creat();
}
من تا امشب وقت دارم لطفا اگه کسی میتونه دریغ نکنه.
ممنون