小工具知识网

当前位置: 首页 > 行业知识 > 数据结构:广义表

行业知识

数据结构:广义表

2026-11-04 21:52:09 来源:互联网转载

定义:���序数列  表示GL=(a(b,c))长度 2,

()

表头:a 表尾:(b,c)符号:head(A)=a ,tail(A)=((b,c))

广义表的表尾一定是个表,具有递归,元素可以是子表,子表里还有子表

()

结构体定义

typedef enum{ATOM,LIST} ElemTag;//ATOM=o,表示原子,LIST表示子表typedef struct GLNode{ElemTag tag;//tafg标识符union{int  atom;struct { struct GLNode*tp,*tp; }htp;//表头,表尾,以及表结点的指针域} atom_htp; //表头,表尾,以及表结点的指针域的联合体域}GLNode,*GList;

顺便查了个union

union 是C语言中一种声明共用体的数据类型。
union(共用体)在某种程度上类似struct(结构体)的一种数据结构,可以包含很多数据结构和变量。
union(共用体)的特点:其内部的数据 共用一个内存首地址,共享同一段内存,以达到节省空间的目的。

#include union Data {   int i;   float f;   char str[20];};int main() {   union Data data;      data.i = 10;   printf("data.i: %d\n", data.i);      data.f = 3.14;   printf("data.f: %f\n", data.f);      strcpy(data.str, "Hello");   printf("data.str: %s\n", data.str);      return 0;}

上一篇:VScode下配置Go语言开发环境【2023最新】

下一篇:海康sip服务器地址怎么设置?