upsidedown

bfs1

Jul 18th, 2012
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include<iostream>
  2. #include<conio.h>
  3. using namespace std;
  4. class calc
  5. {
  6. public:
  7.     int a[20][20];
  8.     int d[10]={0,1,2,3,4,5,6,7,8,9};
  9.     char b[20],c[20],da[20];
  10.  
  11.     void nodes(int x)
  12.     {
  13.         cout<<"enter the nodes:"<<endl;
  14.         for(int i=0;i<x;i++)
  15.             cin>>b[i];
  16.     }
  17.  
  18.     void mak_tree(int x)
  19.     {
  20.         char a;
  21.         for(int i=0;i<x;i++)
  22.         {
  23.             cout<<"enter the valid child nodes of "<<b[i]<<" or 1 if no more nodes"<<endl;
  24.             do
  25.             {
  26.                 cin>>a;
  27.                 place(a,i);
  28.             }while(a!='1');
  29.         }
  30.     }
  31.  
  32.     void place(char a,int x)
  33.     {
  34.         int j;
  35.         for(int i=0;i<x;i++)
  36.         {
  37.             if(b[i]==a)
  38.             {
  39.                 j=i;
  40.                 break;
  41.             }
  42.             else
  43.                 j=99;
  44.             if(j==99)
  45.                 cout<<"invalid input\n";
  46.             else
  47.                 a[x][j]=1;
  48.         }
  49.  
  50.     }
  51.  
  52.     void dfs(char p,int x)
  53.     {
  54.         int k,q,w=0,e=0;
  55.         c[0]=b[0];
  56.         do
  57.         {
  58.             for(int j=0;j<x;j++)
  59.             {
  60.                 if(b[j]==c[e])
  61.                 {
  62.                     k=j;
  63.                     break;
  64.                 }
  65.             }
  66.             for(int i=0;i<x;i++)
  67.             {
  68.                 if(a[k][i]==1)
  69.                     q=i;
  70.                 else
  71.                     q=99;
  72.                 if(q!=99)
  73.                 {
  74.                     d[w]=c[e];
  75.                     c[e]=b[q];
  76.                     e++
  77.                     w++;
  78.                 }
  79.             }
  80.         }while()
  81.     }
  82.  
  83. }
  84.  
  85. int main()
  86. {
  87.     calc s;
  88.     int x,n;
  89.     char p;
  90.     cout<<"enter the number of nodes"<<endl;
  91.     cin>>n;
  92.     for(int i=0;i<n;i++)
  93.         for(int j=0;j<n;j++)
  94.             s.a[i][j]=0;
  95.     s.nodes(n);
  96.     s.mak_tree(n);
  97.     cout<<"enter the final node to traverse till assuming root node is "<<s.b[0]<<" :\n";
  98.     cin>>p;
  99.  
  100.     return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment