《数据结构(严蔚敏版)》学习笔记(一)——常用数据结构定义:

《数据结构(严蔚敏版)》学习笔记(一)——常用数据结构定义:

线性表 {顺序表,单链表,静态单链表,双向链表}; 

栈 { 顺序栈 };

队列 {单链队列,循环队列};

串 {定长顺序串,动态顺序串,块链串};

数组 {顺序数组};

疏矩阵 {三元组顺序表,行逻辑链接顺序表,十字链表};

广义表 {头尾链表,扩展线性链表};

二叉树 {顺序,链式,线索};

树 {双亲表示,孩子表示,孩子兄弟表示};

图 {邻接矩阵,邻接表,十字链表,邻接多重表};


*********************************************************************************************************


线性表(顺序,动态分配):

<span style="font-size:14px;">typedef struct {
	ElemType	*elem;			//基址
	int		length;			//当前长度
	int		listsize;		//分配空间
}SqList;</span>
<span style="font-size:14px;">SqList L.elem = (ElemType *)malloc(LIST_SIZE * sizeof(ElemType));</span>


线性表(单链表):

<span style="font-size:14px;">typedef struct	LNode{
	ElemType	data;
	struct LNode	*next;
}LNode,*Link;				//用Link就可以定义链表了
typedef struct{
	Link	<span style="white-space:pre">	</span>head,tail;
	int	<span style="white-space:pre">	</span>len;
}LinkList;</span>

线性表(静态单链表):

<span style="font-size:14px;">typedef struct{
	ElemType	data;
	int		cur;		//cur为数组下标,亦为元素“指针”
}component,SLinkList[MAXSIZE];</span>

线性表(双向链表):

<span style="font-size:14px;">typedef struct DuLNode{
	ElemType	data;
	struct DuLNode	*prior;
	struct DuLNode	*next;
}DuLNode,*DuLinkList;</span>

栈(顺序):

<span style="font-size:14px;">typedef struct{
	ElemType	*base;
	ElemType	*top;
	int		stacksize;
}SqStack;
SqStack S.base = (ElemType *)malloc(STACK_SIZE * sizeof(ElemType));
S.top = S.base;</span>

队列(单链):

<span style="font-size:14px;">typedef struct QNode{		//和单链表的定义相同
	ElemType	data;
	struct QNode	*next;
}QNode,*QueuePtr;
typedef struct{
	QueuePtr	front;		//要有队头队尾指针
	QueuePtr	rear;
}LinkQueue;</span>

队列(循环,顺序):

<span style="font-size:14px;">typedef struct{
	ElemType	*base;
	int		front;		//类似静态链表用数字表示“指针”
	int		rear;
}SqQueue;
SqQueue Q.base = (ElemType *)malloc(QUEUE_SIZE * sizeof(ElemType));</span>

串(顺序,定长):

<span style="font-size:14px;">typedef unsigned char SString[MAXSTRLEN + 1];		//a.str[0]存串长 ; b.str[STRLEN]存'\0'</span>

串(堆分配):

<span style="font-size:14px;">typedef struct{
	char	<span style="white-space:pre">	</span>*ch;
	int		length;
}HString;
HString T.ch = (char *)malloc(i * sizeof(char));</span>

串(块链):

由多个顺序表构成的链表...

<span style="font-size:14px;">typedef struct Chunk{
	char		ch[CHUNKSIZE];
	struct Chunk	*next;
}Chunk;
typedef	struct{
	Chunk	<span style="white-space:pre">	</span>*head,*tail;
	int		curlen;			//当前长度
}LString;</span>

数组(顺序):

<span style="font-size:14px;">typedef struct{
	ElemType	*base;
	int		dim;			//维数
	int		*bounds;		//维界基址?
	int		*constants;		//函数常量机制?
}Array;
Array A.bounds = (int *)malloc(dim * sizeof(int));
A.base = (ElemType *)malloc(eletotal * sizeof(ElemType));
A.constants = (int *)malloc(dim * sizeof(int));</span>

稀疏矩阵(三元组顺序表):

只记录非0元...

<span style="font-size:14px;">typedef struct{
	int		i,j;
	ElemType	e;
}Triple;			<span style="white-space:pre">		</span>//单个元素
typedef struct{
	Triple		data[MAXSIZE + 1];		//非0元三元组表
	int		mu,nu,tu;				//行数,列数,非0元数
}TSMatrix;</span>

稀疏矩阵(行逻辑链接顺序表):

<span style="font-size:14px;">typedef struct{
	Triple		data[MAXSIZE + 1];
	int		rpos[MAXRC + 1];		//各行第一个非0元位置表
	int		mu,nu,tu;
}RLSMatrix;</span>

稀疏矩阵(十字链表):

<span style="font-size:14px;">typedef struct OLNode{
	int		i,j;
	ElemType	e;
	struct OLNode	*right,*down;		//行/列链表的下一元素
}OLNode,*OLink;
typedef struct{
	OLink		*rhead,*chead;		//行/列链头指针
	int		mu,nu,tu;
}CrossList;</span>

广义表(头尾链表):

<span style="font-size:14px;">typedef enum	{ATOM,LIST}ElemTag;
typedef struct GLNode{
	ElemTag		tag;
	union{
		AtomType	<span style="white-space:pre">	</span>atom;
		struct{struct GLNode	*hp,*tp;}ptr;		//ptr是表节点指针域,ptr.hp/ptr.tp分别指向表头表尾
	};
}*GList;</span><span style="font-size:18px;">								</span><span style="font-size:14px;">//每个原子节点都有对应的表节点</span>

广义表(扩展线性链表):

<span style="font-size:14px;">typedef enum	{ATOM,LIST}ElemTag;
typedef struct GLNode{
	ElemTag		tag;
	union{
		AtomType	atom;
		struct GLNode	*hp;
	};
	struct GLNode	*tp;			//指向下一个节点
}*GList;</span><span style="font-size:18px;">						</span><span style="font-size:14px;">		//原子节点和表节点等价</span>

二叉树(顺序):

<span style="font-size:14px;">typedef ElemType	SqBiTree[MAX_SIZE];		//层次遍历建立</span>

二叉树(链式):

<span style="font-size:14px;">typedef struct BiTNode{
	ElemType	<span style="white-space:pre">	</span>data;
	struct BiTNode	<span style="white-space:pre">	</span>*lchild,*rchild;
}BiTNode,*BiTree;</span>

二叉树(线索):

将叶子节点不用的指针用来指后继...

<span style="font-size:14px;">typedef	enum	PointerTag{Link,Thread};
typedef struct BiThrNode{
	ElemType		data;
	struct BiThrNode	*lchild,*rchild;
	PointerTag		LTag,RTag;
}BiThrNode,*BiThrTree;</span>

树(双亲,顺序):

<span style="font-size:14px;">typedef struct PTNode{
	ElemType	data;
	int		parent;
}PTNode;
typedef struct{
	PTNode	<span style="white-space:pre">	</span>nodes[MAX_SIZE];
	int		r,n;		//根的位置,节点数
}PTree;</span>

树(孩子链表):

<span style="font-size:14px;">typedef struct CTNode{
	int		child;
	struct CTNode	*next;
}*ChildPtr;
typedef struct{
	ElemType	data;
	ChildPtr	firstchild;
}CTBox;
typedef struct{
	CTBox	<span style="white-space:pre">	</span>nodes[MAX_SIZE];
	int		n,r;
}CTree;</span>

树(二叉链表):

<span style="font-size:14px;">typedef struct CSNode{
	ElemType		data;
	struct CSNode	<span style="white-space:pre">	</span>*firstchild,*nextsibling;
}CSNode,*CSTree;</span>

Huffman树:

<span style="font-size:14px;">typedef struct{
	unsigned int	weight;
	unsigned int	parent,lchild,rchild;
}HTNode,*HuffmanTree;			//动态分配数组
typedef char ** HuffmanCode;	//动态分配数组</span>

图(邻接矩阵):

<span style="font-size:14px;">typedef enum	{DG,DN,UDG,UDN}GraphKind;		//有向图,有向网,无向图,无向网
typedef struct ArcCeil{
	VRType		adj;		//顶点关系或权值
	InfoType	*info;
}ArcCeil,AdjMatrix[MAX_VERTEX_NUM][MAX_VERTEX_NUM];	//使用二维矩阵存关系
typedef struct{
	VertexType	vexs[MAX_VERTEX_SIZE];			//点集
	AdjMatrix	arcs;
	int		vexnum,arcnum;					//点数,边数
	GraphKind	kind;
}MGraph;</span>

图(邻接表):

<span style="font-size:14px;">typedef struct ArcNode{
	int			adjvex;				//保存的是头节点的序号
	struct ArcNode	<span style="white-space:pre">	</span>*nextarc;
	InfoType		*info
}ArcNode;
typedef struct VNode{
	VertexType	<span style="white-space:pre">	</span>data;
	ArcNode		<span style="white-space:pre">	</span>*firstarc;
}VNode,AdjList[MAX_VERTEX_NUM];			//将节点作成一个顺序数组
typedef struct{
	AdjList		<span style="white-space:pre">	</span>vertices;
	int			vexnum,arcnum;
	int			kind;
}ALGraph;</span>

有向图(十字链表):

<span style="font-size:14px;">typedef struct ArcBox{
	int			tailvex,headvex;			//弧的尾头节点
	struct ArcBox	<span style="white-space:pre">	</span>*hlink,*tlink;				//同头/尾弧链
	InfoType		*info;
}ArcBox;
typedef struct VexNode{
	VertexType		data;
	ArcBox			*firstin,*firstout;			//入弧链头,出弧链头
}VexNode;
typedef struct{
	VerNode	<span style="white-space:pre">		</span>xlist[MAX_VERTEX_SIZE];
	int		<span style="white-space:pre">	</span>vexnum.arcnum;
}OLGraph;</span>

图(邻接多重表):

和十字链表基本相同...

<span style="font-size:14px;">typedef enum	{unvisited,visited}VisitIf;
typedef struct EBox{
	VisitIf		<span style="white-space:pre">	</span>mark;
	int			ivex,jvex;
	struct EBox	<span style="white-space:pre">	</span>*ilink,*jlink;
	Infotype	<span style="white-space:pre">	</span>*info;
}EBox;
typedef struct VexBox{
	VertexType	<span style="white-space:pre">	</span>data;
	EBox		<span style="white-space:pre">	</span>*firstedge;
}VexBox;
typedef struct{
	VexBox		<span style="white-space:pre">	</span>adjmulist[MAX_VERTEX_SIZE];
	int			vexnum,arcnum;
}AMLGraph;</span>



  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值