没有合适的资源?快使用搜索试试~ 我知道了~
广义表的长度,深度,表头,表尾,表头和表尾的连接,两个广义表的连接等相关算法。
资源推荐
资源详情
资源评论
#include <stdio.h>
#include <malloc.h>
typedef struct lnode
{
int tag;
union
{
char data;
struct lnode *sublist;
}val;
struct lnode *link;
}GLNode;
GLNode *CreatGL (char *&s)
{
GLNode *h; char ch;
ch=*s;
s++;
if (ch!='\0')
{ h=(GLNode *)malloc(sizeof(GLNode));
if (ch=='(')
{ h->tag=1;
h->val.sublist=CreatGL(s);
}
else if (ch==')')
h=NULL;
else
{ h->tag=0;
h->val.data=ch;
}
}
#include <malloc.h>
typedef struct lnode
{
int tag;
union
{
char data;
struct lnode *sublist;
}val;
struct lnode *link;
}GLNode;
GLNode *CreatGL (char *&s)
{
GLNode *h; char ch;
ch=*s;
s++;
if (ch!='\0')
{ h=(GLNode *)malloc(sizeof(GLNode));
if (ch=='(')
{ h->tag=1;
h->val.sublist=CreatGL(s);
}
else if (ch==')')
h=NULL;
else
{ h->tag=0;
h->val.data=ch;
}
}
else h=NULL;
ch=*s;
s++;
if (h!=NULL)
if (ch==',')
h->link=CreatGL(s);
else
h->link=NULL;
return h;
}
void DispGL (GLNode *g)
{
if (g!=NULL)
{
if (g->tag==1)
{ printf("(");
if (g->val.sublist==NULL)
printf("");
else
DispGL (g->val.sublist);
}
else
printf("%c",g->val.data);
if (g->tag==1)
printf(")");
if (g->link!=NULL)
{ printf(",");
DispGL(g->link);
}
}
ch=*s;
s++;
if (h!=NULL)
if (ch==',')
h->link=CreatGL(s);
else
h->link=NULL;
return h;
}
void DispGL (GLNode *g)
{
if (g!=NULL)
{
if (g->tag==1)
{ printf("(");
if (g->val.sublist==NULL)
printf("");
else
DispGL (g->val.sublist);
}
else
printf("%c",g->val.data);
if (g->tag==1)
printf(")");
if (g->link!=NULL)
{ printf(",");
DispGL(g->link);
}
}
剩余13页未读,继续阅读
资源评论
ninghui45
- 粉丝: 59
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功