广工数据结构5.30③ 试按表头、表尾的分析方法重写求广义表 的深度的递归算法。

来源:互联网 发布:如何当一名网络写手 编辑:程序博客网 时间:2024/04/30 15:25
int GListDepth(GList ls)
/* Return the depth of list */
{
    GList pp;
    int max, h, t;
    if(!ls)
        return 1;
    if(ls->tag == ATOM)
        return 0;
    for(pp=ls; pp; pp=pp->un.ptr.tp){
        h = GListDepth(pp->un.ptr.hp)+1;
        t = GListDepth(pp->un.ptr.tp);
        if(h > t)
            return h;
        else
            return t;
    }            
}
0 1
原创粉丝点击