绪论
线性表
- 线性表的基本操作:
- 初始化表:InitList ( &L )
- 销毁操作:DestroyList ( &L )
- 插入操作:LIstInsert ( &L, i, e )
- 删除操作:ListDelete ( &L, i, &e )
- 按值查找:LocateElem ( L, i )
- 按位查找:GetElem ( L, i )
- 其他常用操作
- 求表长:Length ( L )
- 输出操作:PrintList ( L )
- 判空操作:Empty ( L )
线性表的定义和基本操作
** < 顺序表的定义 >**
typedef struct {
int num;
int people
} Customer
线性表的顺序表示
线性表的链式表示
栈、队列、数组
串
树与二叉树
< 二叉树的存储 >
- 二叉树的顺序存储
#define MaxSize 100
struct TreeNode {
ElemType value; // 结点中的数据元素
bool isEmpty; // 结点是否为空
};
TreeNode t[MaxSize];
// 初始化结点标记为空
void InitTree(TreeNode *t){
for (int i=0; i<MaxSize; i++){
t[i].isEmpty = true;
}
}
- 二叉树的链式存储
#include <iostream>
typedef struct BiTNode{
ElemType data;
struct BiTNode *lchild, *rchild;
} BiTNode, *BiTree;
// 三叉链表
typedef struct BiTNode{
ElemType data;
struct BiTNode *lchild, *rchild;
struct BitNode *parent;
} BiTNode, *BiTree;
// 定义一个空树
void InitTree(){
BiTree root = NULL;
}
// 插入根节点
void InsertRoor(){
BiTree root = (BiTree) malloc(sizeof (BiTree));
root->data = {1};
root->lchild = NULL;
root->rchild = NULL;
}
// 插入新节点
void InsertNode(){
BiTNode *p = (BiTNode *) malloc(sizeof (BiTNode));
p->data = {2};
p->lchild = NULL;
p->rchild = NULL;
root->lchild = p;
}
< 树的遍历 >
- 树的后根遍历
// 树的后根遍历
void PostOrder(TreeNode *R){
if ( R != NULL){
while( R还有下一子树T )
PostOrder(T); // 后根遍历下一棵子树
visit(R); // 访问根节点
}
}