سفارش تبلیغ
صبا ویژن
دانش، زمام دار و کردار، راننده و نفس(مرکبی) سرکش است . [امام علی علیه السلام]

سرگرمی

#include<iostream.h>
#include<conio.h>
struct tree
{
int id;
int data;
tree*next1;
tree*next2;
tree*next3;
tree*next4;
tree*next5;
tree*father;
}*h;
/////////////////////////////////////////////////////////////
void make1(tree*fa,int data)
{ cout<<"resha"<<fa->data;
getch();
  tree*node1= new tree;
  node1->data=data;
  node1->next1=0;
  node1->next2=0;
  node1->next3=0;
  node1->next4=0;
  node1->next5=0;
  node1->id=1;
  node1->father=0;
  if(fa->next1!=0)
  {
    cout<<"it is not free";
    getch();
  }
  else
  {
   fa->next1=node1;
   node1->father=fa;
  }
}
////////////////////////////////////////////////////////////////
void make2(tree*p,int data)
{
 tree*node2=new tree;
  node2->data=data;
  node2->next1=0;
  node2->next2=0;
  node2->next3=0;
  node2->next4=0;
  node2->next5=0;
  node2->father=0;
  node2->id=2;
  cout<<"resha"<<p->data;
  getch();
  if(p->next2!=0)
  {
    cout<<"it is not free";
    getch();
  }
  else
  {
    p->next2=node2;
    node2->father=p;
  }
}
//////////////////////////////////////////////////////////
void make3(tree*p,int data)
{
 tree*node3=new tree;
  node3->data=data;
  node3->next1=0;
  node3->next2=0;
  node3->next3=0;
  node3->next4=0;
  node3->next5=0;
  node3->id=3;
  node3->father=0;
  if(p->next3!=0)
  {
    cout<<"it is not free";
    getch();
  }
  else
  {
  p->next3=node3;
  node3->father=p;
  }
}
/////////////////////////////////////////////////////////////
void make4(tree*u,int data)
{
  tree*node4=new tree;
  node4->data=data;
  node4->next1=0;
  node4->next2=0;
  node4->next3=0;
  node4->next4=0;
  node4->next5=0;
  node4->father=0;
  node4->id=4;
  if(u->next4!=0)
  {
    cout<<"it is not free";
    getch();
  }
  else
  {
   u->next4=node4;
   node4->father=u;
  }
}
///////////////////////////////////////////////////////////
void make5(tree*y,int data)
{
 tree*node=new tree;
  node->data=data;
  node->next1=0;
  node->next2=0;
  node->next3=0;
  node->next4=0;
  node->next5=0;
  node->father=0;
  node->id=5;
  if(y->next5!=0)
  {
    cout<<"it is not free";
    getch();
  }
  else
  {
    y->next5=node;
    node->father=y;
  }
}
//////////////////////////////////////////////////////////////
int flag=0;
tree*find(tree*ese,int fi)
{
   if(ese!=0)
   {
     if(ese->data==fi)
     {  flag=1;
       return ese;
     }
     find(ese->next1,fi);
     find(ese->next2,fi);
     find(ese->next3,fi);
     find(ese->next3,fi);
     find(ese->next4,fi);
     find(ese->next5,fi);
   }
}
///////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////
struct dodo
{
  int data;
  dodo *lchild;
  dodo*rchild;
}*h1;
////////////////////////////////////////////////////////////////
dodo*make(int data)
{
  dodo*node=new dodo;
  node->data=data;
  node->lchild=0;
  node->rchild=0;
  return node;
}
////////////////////////////////////////////////////////////////
int flag2=0;
dodo* find_do(dodo*e,int x)
{
   if(e!=0)
   {
     if(e->data==x)
      {
       flag2=1;
       return e;
      }
    find_do(e->lchild,x);
    find_do(e->rchild,x);
   }

}
////////////////////////////////////////////////////////////////////
void change(tree*check)
{
  if(check->father==0)
    h1=make(check->data);
  else
  {
    if(check->id==1)
    {
       flag2=0;
       dodo*q=h1;
       int oo=check->father->data;
       dodo* xx=find_do(q,oo);
       if(flag==1)
       {
       dodo*ll=make(check->data);
       xx->lchild=ll;
       if(check->father->next2!=0)
  {
      dodo*ff=make(check->father->next2->data);
      ll->rchild=ff;
  }
       }
       if(flag2==0)
       {
 cout<<"it is not finde";
 getch();
       }
    }
     else
     {
       if(check->id==2)
       {
   if(check->father->next3!=0)
   {
     dodo*w=make(check->father->next3->data);
     flag2=0;
     dodo*vv=h1;
     dodo*zz=find_do(h1,check->data);
     if(flag2==1)
       zz->rchild=w;
     if(flag2==0)
     {
      cout<<"it is not find";
      getch();
     }
   }
       }
    }

     {
     if(check->id==3)
     {
       if(check->father->next4!=0)
       {
   dodo*mm=make(check->father->next4->data);
   flag2=0;
   dodo*rr=h1;
   dodo*cc=find_do(rr,check->next3->data);
   cc->rchild=mm;
       }
     }

     }
 }
}
void chang(tree*farn)
{
  if(farn!= 0)
  {
     change(farn);
     chang(farn->next1);
     chang(farn->next2);
     chang(farn->next3);
     chang(farn->next4);
     chang(farn->next5);
  }
}
//////////////////////////////////////////////////////////////////////
void show1(dodo* sho)
{

  if(sho!=0)
  {
    cout<<sho->data<<endl;
    show1(sho->lchild);
    show1(sho->rchild);
  }
}
void show3(dodo*sho)
{

  if(sho!=0)
  {

    show3(sho->lchild);
    show3(sho->rchild);
    cout<<sho->data<<endl;
  }
}
void show2(dodo*sho)
{

  if(sho!=0)
  {

    show2(sho->lchild);
    cout<<sho->data<<endl;
    show2(sho->rchild);

  }
}

//////////////////////////////////////////////////////////////////////
void main()
{
  clrscr();
  h=0;h1=0;
  cout<<"plese enter number to make first resha"<<endl;
  int data;
  cin>>data;
  tree*fi;
  fi->data=data;
  fi->next1=0;
  fi->next2=0;
  fi->next3=0;
  fi->next4=0;
  fi->next5=0;
  fi->father=0;
  h=fi;
  clrscr();
  cout<<"if you want to exit plese enter (0)"<<endl;
  int b;
  cin>>b;
  while(b!=0)
  {
     clrscr();
     cout<<"plese enter your number to add:"<<endl;
     int data1;
     cin>>data1;
     cout<<"what resha do you want to add"<<endl;
     int resha;
     cin>>resha;
     tree*a=h;
     flag=0;
     tree*f=find(a,resha);

     if(flag==1)
     {
       cout<<"it is  "<<f->data;
      getch();
       clrscr();
 cout<<"where do  you want to add?plese enter id of it(1,2,3,4,5)"<<endl;
 int id;
 cin>>id;
 if(id==1)
     make1(f,data1);
     else
     if(id==2)
       make2(f,data1);
       else
       if(id==3)
  make3(f,data1)   ;
  else
  if(id==4)
    make4(f,data1);
    else
    make5(f,data1);

     }
   else
   {
     cout<<flag<<"it ia not find"<<endl;
     getch();
   }
   cout<<"if you want to exit enter (0)"<<endl;
   cin>>b;

  }
///////////////////////////////////////////////////////////////////
clrscr();
cout<<"it change to tree binery";
getch();
tree*check1=h;

chang(check1);
dodo*bb=h1;

int ll=1;

while(ll)
{
clrscr();
cout<<"plese enter one iteam to show (pre(1),in(2),pos(3))"<<endl;
int qq;
cin>>qq;
  if(qq==1)
  {
  show1(bb);
  getch();
  }
  else
    if(qq==2)
    {
    show2(bb);
    getch();
    }
     else
   {
     show3(bb);
     getch();
   }
  cout<<"exit==0)";
  cin>>ll;
}


getch();
}




اسماعیل ::: یکشنبه 87/4/23::: ساعت 11:29 عصر

>> بازدیدهای وبلاگ <<
بازدید امروز: 10


بازدید دیروز: 1


کل بازدید :21791
 
 >>اوقات شرعی <<
 
>> درباره خودم<<
 
>>اشتراک در خبرنامه<<
 
 
>>طراح قالب<<