广义表
来源:互联网 发布:瑞典隆德大学知乎 编辑:程序博客网 时间:2024/05/20 10:24
#include#include#include#include//广义表的头尾链表存储结构typedef enum { ATOM, LIST } ELemTag;typedef int AtomType;//ATOM=0,表示原子//List=1,表示子表typedef struct GLNode{ELemTag tag;//用于区别原子节点和表节点union {AtomType atom;//即int atom用作原子类型节点的值域成员struct {struct GLNode *hp, *tp;}htp;//定义了表节点结构体,/*只要是表,就可以递归减小规模,拆成表头表尾,因此只有元素节点中才会存放具体值,表节点中是两个指针,一指表头,一指表尾*/}atom_htpx;//是原子节点值域和表节点指针域的联合体域 }*GList;//广义表//求深度int GListDepth(GList L){if (!L)return 1;//空表深度为1if (L->tag == ATOM){return 0;}GList pp;int dep;int max;for (max = 0, pp = L; pp; pp = pp->atom_htpx.htp.tp){dep = GListDepth(pp->atom_htpx.htp.hp);if (dep > max)max = dep;}return max + 1;}//复制广义表void GListCopy(GList &T, GList L){if (!L)T = NULL;else{T = (GList)malloc(sizeof(GLNode));if (!T)exit(OVERFLOW);T->tag = L->tag;if (L->tag == ATOM){T->atom_htpx.atom = L->atom_htpx.atom;}else{GListCopy(T->atom_htpx.htp.hp, L->atom_htpx.htp.hp);GListCopy(T->atom_htpx.htp.tp, L->atom_htpx.htp.tp);}}}//建立广义表void CreateGList(GList &L, char str[]){if (strcmp(str, "()") == 0)L = NULL;else{if (strlen(str) == 1){L = (GList)malloc(sizeof(GLNode));L->tag = ATOM;L->atom_htpx.atom = str[0];}else{L = (GList)malloc(sizeof(GLNode));L->tag = LIST;SubString()}}}void DestroyGList(GList &L){if (!L)return;if (L->tag == LIST){defstroy }}
阅读全文
0 0
- 广义表
- 广义表
- 广义表
- 广义表
- 广义表
- //广义表
- 广义表
- 广义表
- 广义表
- 广义表
- 广义表
- 广义表
- 广义表
- 广义表
- 广义表
- 广义表
- 广义表
- 广义表
- 07.开源项目--git
- Python自然语言处理第二章-2.5WordNet(IV)——语义相似度
- Windows解压版安装64位Apache2.4.29
- 列表、元组、字典、集合
- Hadoop 简介(Form Imoc)
- 广义表
- QT QThread 简单实现多线程
- 牛客练习赛6 B 点权和 树点权和
- Java集合框架关系图谱
- C++的学习-“C++与C的不同的笔记”
- Ubuntu和Mac使用gdbserver远程调试android源码
- programmers at work---大师们对编程的理解,值得一读
- Hive搭建与基本操作
- 工作容易,赚钱很难