#include
#include
#include
typedef enumelemtag;
struct node;
struct node *tail;
};char a[100];
int len,time;
int max=0;
struct node* dfs(int step)
t=(struct node*)malloc(sizeof(struct node));
if(time==len-1)
if(a[time]=='(') //當遇到「(」時,便建立乙個表頭,然後去尋找它的頭指標和尾指標指向的地方
t->head=dfs(step+1);
time++;
while(a[time]==',')
if(a[time]==')') //無論是表頭還是原子,只要遇到「)」便指向null
return t;
}if(a[time]>='a'&&a[time]<='z')
return t;
}if(a[time]=='(') //如果表頭的尾指標是"(",則他的尾指標指向的地方是表頭
}if(a[time]>='a'&&a[time]<='z') //這種情況他的尾指標指向的位置是乙個原子
t->tail=dfs(step);
return t;
}if(a[time]==')')
}int main()
head1->head=dfs(1);
head1->tail=null;
printf("%d\n%d",max,max);
return 0;
}
廣義表的建立,遍歷,求深度
include typedef char atomtype typedef enum elemtag atom 0,表示原子 list 1,表示子表 typedef struct glnode htp 表結點的指標域htp,包括 表頭指標域hp和表尾指標域tp atom htp atom htp 是...
廣義表的建立
include include include define error 1 define over flow 0 define ok 1 define max str len 100 char hstr max str len char istr max str len typedef int s...
求廣義表深度
試按表頭 表尾的分析方法編寫求廣義表的深度的遞迴程式。輸入一串以 開始,以 結束的字串,並且輸入的左右括號必須匹配,如 分別輸出按表頭 表尾分析方法求廣義表深度的結果,每個結果佔一行。a,b,c,d,e f g include include struct node void creategener...