int GListLength(GList L);//求广义表L的长度
int CopyGList(GList &T,GList L);//由广义表L复制得到广义表T
GLNode *GetHead(GList L);//获取广义表L的表头
GLNode *GetTail(GList L);//获取广义表L的表尾
int GListDepth(GList L);//求广义表L的深度
void visit(AtomType e);//遍历函数
Status GListTraverse(GList &L,void(*visit)(AtomType e));//广义表的遍历
广义表运算举例
D = ( E, F ) = ((a, (b, c)),F )
GetHead( D ) = E
GetHead( E ) = a
GetHead(((b, c))) = (b, c)
GetHead((b, c)) = b
GetHead((c)) = c
GetTail( D ) = ( F )
GetTail( E ) = ((b, c))
GetTail(((b, c))) = ( )
GetTail((b, c)) = (c)
GetTail((c)) = ( )
if (!L) return 1;
if (L->tag == ATOM) return 0;
for (max=0, pp=L; pp; pp=pp->ptr.tp){
dep = GlistDepth(pp->ptr.hp);
if (dep > max) max = dep;
}
return max + 1;
复制广义表Status CopyGList(Glist &T, Glist L)
if (!L) T = NULL; // 复制空表 else {
if ( !(T = new GLNode) ) exit(OVERFLOW); //建表结点
T->tag = L->tag;
if (L->tag == ATOM)
T->atom = L->atom; // 复制单原子结点 else { 分别复制表头和表尾 }
}
else
return OK;