随笔分类 - 数据结构
14、图-邻接矩阵
摘要:1、邻接矩阵的定义和初始化 #include<stdio.h> #include<malloc.h> #include<assert.h> #define Default_Vertices_Size 10 //顶点 #define T char //无向不带权的图 typedef struct Gr
13、线索二叉树
摘要:1、线索化二叉树的定义和初始化 #include<stdio.h> #include<malloc.h> #include<assert.h> #define ElemType char typedef struct BinTreeNode{ ElemType data; struct BinTre
12、二叉树
摘要:1、二叉树的定义和初始化 //二叉树节点定义 typedef struct BinTreeNode{ ElemType data; struct BinTreeNode* leftChild; struct BinTreeNode* rightChild; }BinTreeNode; //二叉树定义
11、稀疏矩阵的压缩存储
摘要:1、稀疏矩阵的压缩存储定义和初始化 #include<stdio.h> #include<stdlib.h> #include<malloc.h> #include<assert.h> #include<memory.h> #define ElemType int #define MAXSIZE 1
10、广义表
摘要:1、广义的定义和初始化 #include<stdio.h> #include<malloc.h> #include<string.h> #include<assert.h> #include<stdlib.h> #define ATOM_TYPE int typedef enum { HEAD, A
9、串的堆分配方式
摘要:1、代码实现 #include<stdio.h> #include<malloc.h> #include<assert.h> #include<string.h> typedef struct HeapString{ char* ch; int length; }HString; //初始化 voi
8、串的顺序存储
摘要:1、代码实现 #include<stdio.h> #include<malloc.h> #include<assert.h> #include<string.h> //"abcdef" => "abcdef/0 // 用数组第一个空间存储字符串长度 5 a b c e f #define MAX_S
7、队列
摘要:1、链队 #include<stdio.h> #include<malloc.h> #include<assert.h> #define ElemType int typedef struct QueueNode{ ElemType data; struct QueueNode* next; }Qu
6、栈
摘要:1、顺序栈 #include<stdio.h> #include<malloc.h> #include<assert.h> #define ElemType int #define STACK_INIT_SIZE 8 #define STACK_INC_SIZE 3 //顺序栈的定义 typedef
5、循环双链表
摘要:#include<stdio.h> #include<assert.h> #include<malloc.h> typedef int ElemType; typedef struct Node{ ElemType data; struct Node* prior; struct Node* nex
4、循环单链表
摘要:1、代码实现 #include<stdio.h> #include<malloc.h> #include<assert.h> typedef int ElemType; typedef struct Node{ ElemType data; struct Node* next; }Node,*PNo
3、静态链表
摘要:1、静态链表初始化 head指向-1代表当前为空链表,pool指向下一个可用空间(在数组下标为2的空间),2指向3,3指向4,最后的指向0表示没有下一个节点,以此链接起来。 2、实现代码 #include<stdio.h> #include<malloc.h> #define MAX_SIZE 20
2、链表
摘要:1、创建链表-无头结点 #include<stdio.h> #include<malloc.h> #include<assert.h> typedef int ElemType; //定义链表 typedef struct ListNode{ ElemType data; struct ListNo
2、链表
摘要:1、链表 链表是一种链式存储的线性表,所有元素的内存地址不一定是连续的。 2、接口设计 链表的大部分接口与 动态数组 是一致的。因此可以将这些方法设计成一个接口List。 public interface List<E> { //元素未找到 public static final int ELEME
1、动态数组
摘要:1、数组 数组是一种顺序存储的线性表,所有的元素的内存地址都是连续的。 2、对象数组 对象数组就是存储一些相关对象地址的数组。如下图所示。 3、null值处理 关于数组中是否可以存储null取决于自身的设计。 注意: 1、如果可以存储null值,那么要对代码中equals()等函数经行相关的逻辑处理