نمایش نتایج 1 تا 2 از 2

نام تاپیک: اشکال در برنامه تبدیل درخت دودویی به نخی

  1. #1

    Tick اشکال در برنامه تبدیل درخت دودویی به نخی

    سلام.من این برنامه رو کامل نوشتم ولی وقتی براش 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();
    }



    من تا امشب وقت دارم لطفا اگه کسی میتونه دریغ نکنه.
    ممنون

  2. #2
    کلاس threadtree سازنده ی پیش فرض نداره و حتما باید هنگام نمونه سازی از آن سازنده ی اون رو یکه یک آرگومان داره فراخوانی کنی:
    void main()
    {
    threadtree t(0);
    t.creat();
    }


    بجای

    #include <iostream.h>

    از
    #include <iostream>

    استفاده کن.
    و این خط رو هم به بعد از آن اضافه کن:
    using namespace std;

تاپیک های مشابه

  1. تقاضایی راهنمایی و کمک در کار با Dreamweaver
    نوشته شده توسط احمد کاوه در بخش طراحی وب (Web Design)
    پاسخ: 4
    آخرین پست: پنج شنبه 29 مهر 1389, 12:41 عصر
  2. آقا چه چیزایی با javascript قابل حل هست چه چیزایی با .net
    نوشته شده توسط odiseh در بخش ASP.NET Web Forms
    پاسخ: 13
    آخرین پست: جمعه 02 فروردین 1387, 04:44 صبح
  3. دوستانی که با interbase آشنایی دارند لطفا راهنمایی کنند
    نوشته شده توسط mehdi_moosavi در بخش بانک های اطلاعاتی در Delphi
    پاسخ: 4
    آخرین پست: شنبه 01 بهمن 1384, 14:11 عصر

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •