
数据结构
孑然夏石
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
二叉堆的实现
#include <stdio.h>#include <stdlib.h>#define minsize 10#define mindata 0struct HeapStruct;//这就是一整个堆typedef struct HeapStruct* Heap;Heap InitializeHeap(int MaxSize);void Destroy(Heap H);void MakeEmpty(Heap H);void Insert(int x, Heap H.原创 2022-02-02 16:21:58 · 854 阅读 · 1 评论 -
哈希表的开放地址实现
#include <stdio.h>#include <stdlib.h>#define MinSize 10typedef unsigned int Index;typedef Index Position;struct HashTbl;typedef struct HashTbl* HashTable;HashTable InitializeTable(int TableSize);void DestroyTable(HashTable H);Posit.原创 2022-01-30 17:57:15 · 185 阅读 · 0 评论 -
哈希表的分散链实现
#include <stdio.h>#include <stdlib.h>#define MinSize 10struct ListNode;typedef struct ListNode* Position;struct HashTabl;typedef struct HashTbl* HashTable;struct ListNode { int element; Position next;};typedef Position List;struc.原创 2022-01-30 15:28:12 · 138 阅读 · 0 评论 -
AVL树的实现
struct AVLNode;typedef struct AVLNode* Position;typedef struct AVLNode* AT;AT MakeEmpty(AT T);Position Find(int x, AT T);Position FindMin(AT T);Position FindMax(AT T);AT Insert(int x, AT T);AT Delete(int x, AT T);struct AVLNode { int element;.原创 2022-01-30 09:50:53 · 117 阅读 · 0 评论 -
Dijkstra算法(第一版)(邻接表)
#include <stdio.h>#include <stdbool.h>#define NotAVertex -1#define NumVertex 7typedef int Vertex;typedef int DistType;typedef int WeightType;typedef struct { int i; }list;struct TableEntry { list header; int known; Vertex path; D.原创 2021-10-11 15:34:50 · 169 阅读 · 0 评论 -
邻接表建立图
要吐了,typedef东西太多了,完全记不住......#include <stdio.h>#define MaxVNum 10typedef int Vertex;typedef int WeightType;typedef struct AdjNode* EdgeListNode;struct AdjNode { Vertex NodeName; WeightType weight; struct Adjnode* next;/*是指向下一个点,但点里面不是只有no原创 2021-10-08 21:01:40 · 387 阅读 · 0 评论 -
直接写出后序遍历(由先序遍历和中序遍历数组结果)
/*根据先序遍历和中序遍历的数组结果,直接写出后序遍历的数组*//*in_head和pre_head从0开始*/void solve(int root_in_pre, int in_head, int post_head, int current_tree_len){ /*pre_head用来决定什么写入post, 递归左边就要加+1, 递归右边要加上左子树长度*/ /*in_head决定从哪里开始找,拿根节点划分更新子树长度,递归左边不用动,递归右边就要+左子树长度+1*/ /*post...原创 2021-10-08 16:19:46 · 345 阅读 · 0 评论 -
用最小堆把一列数排成完全二叉树
其实少了一个排序算法,但我们假设从小到大排好了。/*完全二叉搜索树,假设0用上了,注意弄清下标和个数之间的关系*/#include <math.h>int GetLeftLen(int num){ int left, temp = 1; while (temp < num) temp *= 2; /*虽然多了,但恰好是层数*/ int k = (pow(2, temp) - 1) - pow(2, temp - 2); /*k代表了左子树最后一个下标,有t层至多原创 2021-10-08 16:17:39 · 156 阅读 · 0 评论 -
判断二叉树是否同构(运行不成功)
/*判断两个二叉树是否同构*//*输入形式如a 1 2b 3 4c 5 -d - -e 6 -g 7 -f - -h - -*//**********************************/#define max 10#define tree int#define NULL -1#include <stdio.h>/*构建静态链表的结构数组单元*/struct TreeNode{ char data; tree left; tree right;.原创 2021-09-20 17:53:58 · 120 阅读 · 0 评论 -
二叉树 三种遍历的实现(递归)
要求:代码:/*完美通过先序遍历二叉树*//*输出应当为124583697*/#include <stdio.h>typedef struct TreeNode* position;struct TreeNode { int data; position left; position right;};void attatch(position a, position b);void preorder(position a);int main(void).原创 2021-09-19 22:09:29 · 103 阅读 · 0 评论 -
吐了吐了 多项式的addition和multiplication 有bug不想改了
/*Polynomials*/#include <stdio.h>#include <stdlib.h>struct node { int coef; int exp; struct node* next;};typedef struct node* Poly;void attach(int c, int e, Poly rear){ Poly new = malloc(sizeof(struct node)); new->coef = c; n.原创 2021-09-18 17:12:48 · 118 阅读 · 0 评论 -
五、队列的实现(有bug)
#define max 6struct QueueRecord;typedef struct QueueRecord* Queue;Queue Create_Queue(int maxsize);void MakeEmpty(Queue q);void DisposeQueue(Queue q);int Is_Empty(Queue q);int Is_Full(Queue q);void Enque(Queue q);int Dequeue(Queue q);struct Qu.原创 2021-09-14 11:47:08 · 85 阅读 · 0 评论 -
四、用序列链表实现堆栈
ptrls就是悬在外面,指明地址,本身的data没有用,这点区别强调一下。#include <stdio.h>/*用链表实现堆栈, O->O->O->O 那肯定用左边*/struct LSNode { int data; struct LSNode* next;};typedef struct LSNode* LS;/*建立空linked_stack*/LS make_empty_linked_stack(void){ LS ptrls = mallo原创 2021-09-13 17:24:45 · 75 阅读 · 0 评论 -
三、堆栈的一般(数组)实现
#include <stdio.h>#define max 20/*通常用一维数组来实现堆栈*/typedef struct SNode* stack;/*stack->stack*/struct SNode { int data[max]; int top;/*下标,就是最后一个数,不是指向它后面的空位置*/};/*建立空栈*/stack make_empty_stack(void){ stack ptrs = malloc(sizeof(struct SNode.原创 2021-09-13 16:13:15 · 111 阅读 · 0 评论 -
二、链表的一般实现
#include <stdio.h>/*链表的一般实现*/typedef struct LNode* list;struct LNode { int value; struct LNode* next;};/*建立一个空表*/list make_empty(void) { list head = malloc(sizeof(struct LNode)); head->next = NULL; return;}/*求表长*/int length(list p.原创 2021-09-13 12:31:19 · 62 阅读 · 0 评论 -
一、链表的数组实现
链表的数组实现#include <stdio.h>/*链表的数组实现*/#define max 20typedef struct LNode* list;struct LNode { int data[10];/*假设有10个*/ int last;/*从0开始,是数组下标,不是第几个位置*/};/*建立空表*/list make_empty(void){ list ptrL; ptrL = malloc(sizeof(struct LNode)); ptrL原创 2021-09-13 10:07:06 · 318 阅读 · 0 评论