#include #include typedef char elemtype; struct glnode { int tag; union { elemtype data; glnode *sublist; }; glnode *next; }; int lenth ( glnode *gl ) { if ( gl!=NULL ) return 1+lenth ( gl->next ); else return 0; } int depth ( glnode *gl ) { int max=0; while ( gl!=NULL ) { if ( gl->tag==1 ) { int dep=depth ( gl->sublist ); if ( dep>max ) max=dep; } gl=gl->next; } return max+1; } void create ( glnode *&gl ) { char ch; cin>>ch; if ( ch=='#' ) gl=NULL; else if ( ch=='(' ) { gl=new glnode; gl->tag=1; create ( gl->sublist ); } else { gl=new glnode; gl->tag=0; gl->data=ch; } cin>>ch; if ( gl==NULL ) ; else if ( ch==',' ) create ( gl->next ); else if ( ( ch==')' ) || ( ch==';' ) ) gl->next=NULL; } void print ( glnode *&gl ) { if ( gl->tag==1 ) { cout<<'('; if ( gl->sublist==NULL ) cout<<'#'; else print ( gl->sublist ); cout<<')'; } else cout<data; if ( gl->next!=NULL ) { cout<<','; print ( gl->next ); } } void main( ) { glnode *g; create ( g ); print ( g ); cout<sublist ) <sublist ) <