首页 > 其他 > 详细

数据结构之广义表

时间:2016-04-20 23:38:49      阅读:169      评论:0      收藏:0      [点我收藏+]
#include<stdio.h>
//广义表的头尾链表存储结构
typedef int AtomType;
typedef enum NodeType{ATOM,LIST}ElemTag;//ATOM表示原子结点,LIST表示表节点 
typedef struct GLNode{
	ElemTag tag;
	union{
		AtomType atom;
		struct List{
			struct GLNode* hp,*tp;
		
		} htp;
	}atom_htp;
	
	
}GLNode,*GList;

//求广义表L的表头
GList Head(GList L)
{
	if(L==NULL)
	return NULL;
	if(L->tag==ATOM)
		exit(0);
	else 
	return (L->atom_htp->htp->hp);
} 

//求广义表L的表尾
GList Tail(GList L)
{
	
	if(L==NULL)
	return NULL;
	if(L->tag==ATOM)
		exit(0);
	else 
	return (L->atom_htp->htp->tp);
} 

//求广义表的长度
int Length(GList L)
{
	int k=0;
	GLNode* s;
	if(L==NULL)
		return NULL;
	if(L->tag==ATOM)
		exit(0);
	s=L;
	while(s!=NULL)
	{
		k++;
		s=s->atom_htp->htp->tp;
	}
	return k;
} 

//求广义表的深度
 int Depth(GList L)
 {
 	
 	
 	
 } 

  

数据结构之广义表

原文:http://www.cnblogs.com/YTYMblog/p/5414720.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!