廣義表的建立,遍歷,求深度

2021-05-02 01:13:13 字數 1101 閱讀 1088

#include

typedef char atomtype;

typedef enum elemtag; /* atom=0,表示原子;list=1,表示子表*/

typedef struct glnode

htp; /*表結點的指標域htp, 包括

表頭指標域hp和表尾指標域tp*/

}atom_htp; /* atom_htp 是原子結點的值域atom和表結點的指標域htp的聯合體域*/

}*glist;

/**********用於遍歷************/

structfind;

static int num = 0;

void glist_view(glist);/*遍歷*/

/**********用於遍歷結束************/

/**********用於建立************/

typedef structnear;

typedef struct nextnext;

next *strn;

char lin[10];

glist getgeneralized_list(glist,char*);/*建立*/

/**********用於建立結束************/

int getdepth(glist);

main()

glist getgeneralized_list(glist pre,char *p)

if(*p==')')

if(*p==',')

else }

}}if(*p=='/0' && isnum==0)

elseelse}}

}/*列印廣義表*/   

void glist_view(glist p)

num++;

glist_view(p->atom_htp.htp.hp);

}else}}

/*求廣義表深度*/

int getdepth(glist p)

if(p==null)

for(;p;p=p->atom_htp.htp.tp)

return lmax+1;

}

求廣義表深度

試按表頭 表尾的分析方法編寫求廣義表的深度的遞迴程式。輸入一串以 開始,以 結束的字串,並且輸入的左右括號必須匹配,如 分別輸出按表頭 表尾分析方法求廣義表深度的結果,每個結果佔一行。a,b,c,d,e f g include include struct node void creategener...

求廣義表深度(嚴5 30)

試按表頭 表尾的分析方法編寫求廣義表的深度的遞迴程式。輸入一串以 開始,以 結束的字串,並且輸入的左右括號必須匹配,如 分別輸出按表頭 表尾分析方法求廣義表深度的結果,每個結果佔一行。include include include typedef char elemtype typedef stru...

廣義表的建立及求其深度

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 mall...