2.1 线性表基本操作
InitList(&L)
Length(L)
LocateElem(L,e)
GetElem(L,i)
ListInsert(&L,i,e)
ListDelete(&L,i,e)
PrintList(L)
Empty(L)
DestroyList(&L)
2.2 顺序表的定义
#define MaxSize 50
typedef struct {
ElemType data[MaxSize];int length;
}SqList;
2.3 单链表的定义
typedef struct LNode{
ElemType data;
struct LNode* next;
}LNode,*LinkList;
2.4 静态链表的定义
typedef struct{
ElemType data;
int next;
}SLinkList[MaxSize];
3.1 栈的基本操作
InitStack(&S)
StackEmpty(S)
Push(&S,x)
Pop(&S,x)
GetTop(S,&x)
DestroyStack(&S)
3.2 顺序栈存储类型描述
typedef struct{
ElemType data[MaxSize];
int top;
}SqStack;
3.3 栈的链式存储
typedef struct Linknode{
ElemType data;
struct Linknode* next;
}*LiStack;
3.4 队列的基本操作
InitQueue(&Q)
QueueEmpty(Q)
EnQueue(&Q,x)
DeQueue(&Q,&x)
GetHead(Q,&x)
3.5 顺序存储类型定义
typedef struct{
ElemType data[MaxSize];
int front,rear;
}SqQueue;
3.6 链式存储
typedef struct Linknode{
ElemType data;
struct Linknode* next;
}Linknode;
typedef struct{
Linknode *front,*rear;
}LinkQueue;
4.1 简单的模式匹配算法
int Index(SString S,SString T)
{
int i = 1,j = 1;
while (i <= S.length && j <= T.length) {
if (S.ch[i] == T.ch[j]) {
++i;++j;
} else {
i = i-j+2;j = 1;
}
}
if (j > T.length) {
return i-T.length;
} else return 0;
}
4.2 KMP
void get_next(String T,int next[])
{
int i = 1,j = 0;
next[1] = 0;
while (i < T.length) {
if(j == 0||T.ch[i]==T.ch[j]) {
++i;++j;
next[i] = j;
} else {
j = next[j];
}
}
}
int Index_KMP(String T,String S,int next[])
{
int i = 1,j = 1;
while (i <= S.length&&j <= T.length) {
if (j == 0||S.ch[i] == T.ch[j]) {
++i;++j;
} else {
j = next[j];
}
}
if (j > T.length) {
return i - T.length;
} else
return 0;
}
手算
n
e
x
t
next
next 数组
4.3 改进的next
void get_nextval(String T,int nextval[])
{
int i = 1,j = 0;nextval[1] = 0;
while (i < T.length) {
if (j == 0||T.ch[i] == T.ch[j]) {
++i;++j;
if (T.ch[i]!=T.ch[j]) nextval[i] = j;
else nextval[i] = nextval[j];
} else {
j = nextval[j];
}
}
}
5.1 二叉树链式存储结构
typedef struct BiTNode {
ElemType data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
5.2 二叉线索树存储结构
typedef struct ThreadNode{
ElemType data;
struct ThreadNode *lchild,*rchild;
int ltag,rtag;
}ThreadNode,*ThreadTree;
5.3 树,森林存储结构
typedef struct{
ElemType data;
int parent;
}PTNode;
typedef struct {
PTNode nodes[MaxSize];
int n;
}PTree;
typedef struct CSNode{
ElemType data;
strcut CSNode *firstchild,*nextsibling;
}CSNode,*CSTree;
6.1 图的邻接矩阵
typedef struct{
VertexType Vex[MaxVertexNum];
EdgeType Edge[MaxVertexNum][MaxVertexNum];
int vexnum,arcnum;
}MGraph;
6.2 图的邻接表存储
typedef struct ArcNode{
int adjvex;
struct ArcNode *next;
}ArcNode;
typedef struct VNode{
VertexType data;
ArcNode *first;
}VNode ,AdjList[MaxVertexNum];
typedef struct{
AdjList vertices;
int vexnum,arcnum;
}ALGraph;
6.3 图的基本操作
Adjacent(G,x,y)
Neighbors(G,x)
InsertVertex(G,x)
DeleteVertex(G,x)
AddEdge(G,x,y)
RemoveEdge(G,x,y)
FirstNeighbor(G,x)
NextNeighbor(G,x,y)
Get_edge_value(G,x,y)
Set_edge_value(G,x,y,v)