• 王道数据结构2-6章数据结构存储结构定义及基本操作


    2.1 线性表基本操作
    InitList(&L)       //初始化表
    Length(L)           //求表长
    LocateElem(L,e)     //按值查找
    GetElem(L,i)        //按位查找,获取表L中第i个位置的元素
    ListInsert(&L,i,e)  //插入操作,第i个位置插入指定元素
    ListDelete(&L,i,e)  //删除操作,删除第i个位置的元素
    PrintList(L)        //输出操作
    Empty(L)            //判空操作,如果是空表,则返回true
    DestroyList(&L)     //销毁操作
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    2.2 顺序表的定义
    #define MaxSize 50
    typedef struct {
        ElemType data[MaxSize];int length;
    }SqList;
    
    • 1
    • 2
    • 3
    • 4
    2.3 单链表的定义
    typedef struct LNode{
        ElemType data;
        struct LNode* next;
    }LNode,*LinkList;
    
    • 1
    • 2
    • 3
    • 4
    2.4 静态链表的定义
    typedef struct{
        ElemType data;
        int next;
    }SLinkList[MaxSize];
    
    • 1
    • 2
    • 3
    • 4
    3.1 栈的基本操作
    InitStack(&S)
    StackEmpty(S)           //判断是否为空
    Push(&S,x)
    Pop(&S,x)
    GetTop(S,&x)
    DestroyStack(&S)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    3.2 顺序栈存储类型描述
    typedef struct{
        ElemType data[MaxSize];
        int top;
    }SqStack;
    
    • 1
    • 2
    • 3
    • 4
    3.3 栈的链式存储
    typedef struct Linknode{
        ElemType data;
        struct Linknode* next;
    }*LiStack;
    
    • 1
    • 2
    • 3
    • 4
    3.4 队列的基本操作
    InitQueue(&Q)
    QueueEmpty(Q)
    EnQueue(&Q,x)
    DeQueue(&Q,&x)
    GetHead(Q,&x)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    3.5 顺序存储类型定义
    typedef struct{
        ElemType data[MaxSize];
        int front,rear;
    }SqQueue;
    
    • 1
    • 2
    • 3
    • 4
    3.6 链式存储
    typedef struct Linknode{
        ElemType data;
        struct Linknode* next;
    }Linknode;
    typedef struct{
        Linknode *front,*rear;
    }LinkQueue;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    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;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    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;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    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];
            }
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    5.1 二叉树链式存储结构
    typedef struct BiTNode {
        ElemType data;
        struct BiTNode *lchild,*rchild;
    }BiTNode,*BiTree;
    
    • 1
    • 2
    • 3
    • 4
    5.2 二叉线索树存储结构
    typedef struct ThreadNode{
        ElemType data;
        struct ThreadNode *lchild,*rchild;
        int ltag,rtag;
    }ThreadNode,*ThreadTree;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    5.3 树,森林存储结构
    //双亲表示法
    typedef struct{
        ElemType data;
        int parent;
    }PTNode;
    typedef struct {
        PTNode nodes[MaxSize];
        int n;
    }PTree;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    
    //孩子兄弟表示法
    typedef struct CSNode{
        ElemType data;
        strcut CSNode *firstchild,*nextsibling;//第一个孩子和右兄弟指针
    }CSNode,*CSTree;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    6.1 图的邻接矩阵
    typedef struct{
        VertexType Vex[MaxVertexNum];
        EdgeType Edge[MaxVertexNum][MaxVertexNum];
        int vexnum,arcnum;
    }MGraph;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    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;//ALGraph是以邻接表存储的图类型
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    6.3 图的基本操作
    Adjacent(G,x,y)         //判断图是否存在边
    Neighbors(G,x)          //列出图G中与结点x邻接的边
    InsertVertex(G,x)       //在图中插入顶点x
    DeleteVertex(G,x)       //在图中删除顶点x
    AddEdge(G,x,y)          //添加
    RemoveEdge(G,x,y)       //删除该边
    FirstNeighbor(G,x)      //求图中顶点x的第一个邻接点,返回顶点号
    NextNeighbor(G,x,y)     //假设顶点y是顶点x的一个邻接点,返回除y之外的顶点x的下一个邻接点的顶点号
    Get_edge_value(G,x,y)   //获取权值
    Set_edge_value(G,x,y,v) //设置权值
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
  • 相关阅读:
    Android JNI代码语法解释
    架构孪生:架构的数字化形态???
    大白话讲讲 Go 语言的 sync.Map(二)
    Linux基础知识与实操-篇五:bash使用进阶
    【Vue十三】-- Vuex详细介绍
    SpringCloud微服务技术栈-什么是Docker?怎么安装Docker?
    提高C++性能的编程技巧
    图论模板——费用流(无法处理负环)
    基于ffmpeg进行视频解码
    基于 PostgreSQL 构建 AI 电商产品图片相似度搜索方案
  • 原文地址:https://blog.csdn.net/qq_46264636/article/details/126089228