当前位置: 首页> 汽车> 时评 > 安徽省建设厅证件查询官网_中国建筑集团有限公司怎么样_电脑编程培训学校哪家好_新东方教育培训机构

安徽省建设厅证件查询官网_中国建筑集团有限公司怎么样_电脑编程培训学校哪家好_新东方教育培训机构

时间:2025/7/11 19:00:42来源:https://blog.csdn.net/2305_78057683/article/details/145929702 浏览次数: 0次
安徽省建设厅证件查询官网_中国建筑集团有限公司怎么样_电脑编程培训学校哪家好_新东方教育培训机构

typedef enum
{ATOM,LIST
}Nodetype;//枚举类型
typedef struct GLnode
{Nodetype tag;//原子 或者 子表union {char atom;//字母struct{struct GLnode* head;struct GLndoe* tail;};};
}GLnode;
//创建原子结点
GLnode* createAtom(char data)
{GLnode* newnode = (GLnode*)malloc(sizeof(GLnode));if (newnode == NULL){perror("error");exit(1);}newnode->tag = ATOM;newnode->atom = data;return newnode;
}
//创建子表结点
GLnode* createList(GLnode* head, GLnode* tail)
{GLnode* newnode = (GLnode*)malloc(sizeof(GLnode));if (newnode == NULL){perror("error");exit(1);}newnode->tag = LIST;newnode->head = head;newnode->tail = tail;return newnode;
}
//打印广义表
void printNode(GLnode* node)
{if(node == NULL){printf("()");}if (node->tag == ATOM){printf("%c", node->atom);}else{printf("(");GLnode* pcur = node;while (pcur){printNode(pcur->head);if (pcur->tail != NULL){printf(",");}pcur = pcur->tail;}printf(")");}
}
int main()
{GLnode* atomA = createAtom('a');GLnode* atomB = createAtom('b');GLnode* atomC = createAtom('c');GLnode* atomD = createAtom('d');GLnode* suiblist = createList(atomA, createList(atomB, NULL));GLnode* list = createList(atomC, createList(suiblist,createList(atomD,NULL)));printNode(list);printf("\n");printNode(suiblist);}

 

关键字:安徽省建设厅证件查询官网_中国建筑集团有限公司怎么样_电脑编程培训学校哪家好_新东方教育培训机构

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: