第九周项目4--广义表算法库及应用2
来源:互联网 发布:windows ad域博客 编辑:程序博客网 时间:2024/05/23 18:15
#include <stdio.h>
#include "glist.h"
int atomnum(GLNode *g) //求广义表g中的原子个数
{
if (g!=NULL)
{
if (g->tag==0)
return 1+atomnum(g->link);
else
return atomnum(g->val.sublist)+atomnum(g->link);
}
else
return 0;
}
ElemType maxatom(GLNode *g) //求广义表g中最大原子
{
ElemType max1,max2;
if (g!=NULL)
{
if (g->tag==0)
{
max1=maxatom(g->link);
return(g->val.data>max1?g->val.data:max1);
}
else
{
max1=maxatom(g->val.sublist);
max2=maxatom(g->link);
return(max1>max2?max1:max2);
}
}
else
return 0;
}
int main()
{
GLNode *g;
char *s="(b,(b,a,(#),d),((a,b),c((#))))";
g = CreateGL(s);
DispGL(g);
printf("\n");
printf("原子个数 :%d\n", atomnum(g));
printf("最大原子 :%c\n", maxatom(g));
return 0;
}
#include "glist.h"
int atomnum(GLNode *g) //求广义表g中的原子个数
{
if (g!=NULL)
{
if (g->tag==0)
return 1+atomnum(g->link);
else
return atomnum(g->val.sublist)+atomnum(g->link);
}
else
return 0;
}
ElemType maxatom(GLNode *g) //求广义表g中最大原子
{
ElemType max1,max2;
if (g!=NULL)
{
if (g->tag==0)
{
max1=maxatom(g->link);
return(g->val.data>max1?g->val.data:max1);
}
else
{
max1=maxatom(g->val.sublist);
max2=maxatom(g->link);
return(max1>max2?max1:max2);
}
}
else
return 0;
}
int main()
{
GLNode *g;
char *s="(b,(b,a,(#),d),((a,b),c((#))))";
g = CreateGL(s);
DispGL(g);
printf("\n");
printf("原子个数 :%d\n", atomnum(g));
printf("最大原子 :%c\n", maxatom(g));
return 0;
}
0 0
- 第九周-项目4-广义表算法库及应用
- 第九周 项目4-广义表算法库及应用
- 第九周项目4-广义表算法库及应用
- 第九周项目4-广义表算法库及应用
- 第九周项目4-广义表算法库及应用
- (第九周项目4)广义表算法库及应用
- 第九周项目4-广义表算法库及应用
- 第九周项目4-广义表算法库及应用
- 第九周--项目4-广义表算法库及应用
- 第九周项目4-广义表算法库及应用
- 第九周 项目4-广义表算法库及应用
- 第九周 项目4-广义表算法库及应用
- 第九周项目4-广义表算法库及应用
- 第九周项目4-广义表算法库及应用
- 第九周项目4-广义表算法库及应用
- 第九周项目4-广义表算法库及应用
- 【第九周项目4-广义表算法库及应用】
- 第九周 项目4 广义表算法库及应用
- 第九周项目4--广义表算法库及应用1
- 数据库基础知识2
- spark与hadoop对比
- [Linux]多线程同步之pthread_cond_wait()学习笔记
- c语言基本数据类型
- 第九周项目4--广义表算法库及应用2
- 第十周项目1--二叉树算法库
- odroid x2安装ubuntu系统,HDMI显示,说说折腾事儿。
- JSP中的JavaBean和动作元素(四)
- 百度地图 公交查询 redis入门
- NodeJS+express+ajax的简单post登录应用
- socket 套接字编程
- 第十周项目2--二叉树遍历的递归算法
- How To Use Git Effectively