Description
试按表头、表尾的分析方法编写求广义表的深度的递归程序。
Input
输入一串以‘(’开始,以‘(’结束的字符串,并且输入的左右括号必须匹配,如:(),(())……
Output
分别输出按表头、表尾分析方法求广义表深度的结果,每个结果占一行。
-
Sample Input
((a,b,(c,(d,e),f)),g)
-
Sample Output
4 4
#include<stdio.h>
#include<stdlib.h>
typedef char ElemType;
typedef struct Inode{
int tag;
union{
ElemType data;
struct Inode *head;
}val;
struct Inode *tail;
}GLNode;
GLNode *CreateGL(char *&p){
GLNode *g;
char a=*p++;
if(a != '\n'){
g = (GLNode*)malloc(sizeof(GLNode));
if(a == '('){