Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<conio.h>
- using namespace std;
- class calc
- {
- public:
- int a[20][20];
- int d[10]={0,1,2,3,4,5,6,7,8,9};
- char b[20],c[20],da[20];
- void nodes(int x)
- {
- cout<<"enter the nodes:"<<endl;
- for(int i=0;i<x;i++)
- cin>>b[i];
- }
- void mak_tree(int x)
- {
- char a;
- for(int i=0;i<x;i++)
- {
- cout<<"enter the valid child nodes of "<<b[i]<<" or 1 if no more nodes"<<endl;
- do
- {
- cin>>a;
- place(a,i);
- }while(a!='1');
- }
- }
- void place(char a,int x)
- {
- int j;
- for(int i=0;i<x;i++)
- {
- if(b[i]==a)
- {
- j=i;
- break;
- }
- else
- j=99;
- if(j==99)
- cout<<"invalid input\n";
- else
- a[x][j]=1;
- }
- }
- void dfs(char p,int x)
- {
- int k,q,w=0,e=0;
- c[0]=b[0];
- do
- {
- for(int j=0;j<x;j++)
- {
- if(b[j]==c[e])
- {
- k=j;
- break;
- }
- }
- for(int i=0;i<x;i++)
- {
- if(a[k][i]==1)
- q=i;
- else
- q=99;
- if(q!=99)
- {
- d[w]=c[e];
- c[e]=b[q];
- e++
- w++;
- }
- }
- }while()
- }
- }
- int main()
- {
- calc s;
- int x,n;
- char p;
- cout<<"enter the number of nodes"<<endl;
- cin>>n;
- for(int i=0;i<n;i++)
- for(int j=0;j<n;j++)
- s.a[i][j]=0;
- s.nodes(n);
- s.mak_tree(n);
- cout<<"enter the final node to traverse till assuming root node is "<<s.b[0]<<" :\n";
- cin>>p;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment