![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构与算法
zstxxd
此情可待成追忆,当时只道是寻常。
展开
-
【数据结构与算法】十大排序算法及其C语言代码(冒泡,选择,插入,希尔,堆,快速,归并,计数,基数,桶)
排序算法:排序算法的稳定性:当待排序的数据中有相同的数据,排序算法是否会更改它们的前后关系,不会更改的叫稳定排序,可能会更改的叫不稳定排序。冒泡:特点:对数据的有序性敏感是否稳定:稳定时间复杂度:O(n) O(n^2)空间复杂度:O(1)void bubble_sort(int* arr,size_t len){ bool flag = true; for(int i=len-1; i>0 && flag; i--) { flag = false; fo原创 2021-08-31 17:07:22 · 345 阅读 · 0 评论 -
【数据结构与算法】算法的特性以及查找算法(顺序,二分,哈希,块)
什么是算法:广义:解决特定问题的方法。狭义:数据结构具备的功能。算法的特征:有穷性、确切性、输入项、输出项、可行性算法的评定:正确性、时间复杂度、空间复杂度、可读性、健壮性时间复杂度:一个用于描述算法在执行时,随着输入参数数量的变化,而执次数发生变化的函数。一般采用大O表示法:O(函数)常见的时间杂度:常数阶 O(1)对数阶 O(logn)线性阶 O(n)线性对数阶 O(nlogn)平方阶 O(n?)指数阶 O(2^n)空间复杂度:一个用于描述算法在执行时,随着输入参数数原创 2021-08-19 19:33:17 · 249 阅读 · 0 评论 -
【数据结构与算法】十字链表的图的功能实现
为了解决用邻接表存储入度计算复杂的问题,由邻接表升级为十字链表,保存了顶点的出度和入度情况。#include <stdio.h>#include <stdlib.h>#include <stdbool.h>#include <string.h>//边typedef struct Edge{ int in; int out; struct Edge* in_next; struct Edge* out_next; //void* inf原创 2021-08-19 18:47:55 · 129 阅读 · 0 评论 -
【数据结构与算法】链式栈的功能实现
#ifndef STACK_LIST_H#define STACK_LIST_H#include <stdio.h>#include <stdlib.h>#include <stdbool.h>typedef struct Node{ void* data; struct Node* next;}Node;typedef struct StackList{ Node* top; size_t cnt;}StackList;// 创建结点原创 2021-08-18 19:21:22 · 68 阅读 · 0 评论 -
【数据结构与算法】链式队列的功能实现
#ifndef QUEUE_LIST_H#define QUEUE_LIST_H#include <stdio.h>#include <stdlib.h>#include <stdbool.h>typedef struct Node{ void* data; struct Node* next;}Node;//创建节点Node* create_node(void* data);typedef struct QueueList{ Node*原创 2021-08-18 19:17:48 · 71 阅读 · 0 评论 -
【数据结构与算法】用图的邻接表来遍历
#include <stdio.h>#include <stdlib.h>#include <stdbool.h>#include <string.h>typedef struct Edge{ int index; struct Edge* next;}Edge;Edge* create_edge(int index){ Edge* edge = malloc(sizeof(Edge)); edge->index = inde原创 2021-08-09 20:35:55 · 88 阅读 · 0 评论 -
【数据结构与算法】用图的邻接矩阵来遍历
#include <stdio.h>#include <stdlib.h>#include <stdbool.h>#include <string.h>typedef struct Graph{ char* vertex; char* edge; size_t vexnum;}Graph;Graph* create_graph(char* str){ // 申请图所需要的存储空间 Graph* graph = malloc(si原创 2021-08-09 20:34:55 · 102 阅读 · 0 评论 -
【数据结构与算法】关于图的那些概念和存储
文章目录图一、图的相关术语:二、有向图与无向图1.无向图2.有向图3.举个栗子三、图的存储1.邻接矩阵2.邻接表3.十字链表四.图的遍历图 图结构:任意两个数据元素之间都可能存在关系,可以是多对多的关系。一、图的相关术语:顶点:在图型结构中,数据元素被称为顶点。弧:从顶点V1出发,可以到达顶点V2,这种关系被称为弧,用<V1,V2>表示,V1被称为弧尾,V2被称为弧头,这种图被称为有向图。边:从顶点V1可以到达顶点V2,顶点V2可以到达顶点V1,这种关系被称为..原创 2021-08-09 20:28:20 · 220 阅读 · 0 评论 -
【数据结构与算法】平衡二叉查找树的功能实现
#include <stdio.h>#include <stdlib.h>#include <stdbool.h>typedef struct TreeNode{ int data; struct TreeNode* left; struct TreeNode* right; int hight;}TreeNode;TreeNode* create_node(int data){ TreeNode* node = malloc(sizeof(T原创 2021-08-06 19:17:52 · 80 阅读 · 0 评论 -
【数据结构与算法】堆二叉树的功能实现
#include <stdio.h>#include <stdlib.h>#include <stdbool.h>#include <string.h>#include <time.h>//do~while为了使替换语句使用时不加分号会报错#define swap(a,b) do{typeof(a) t=a; a=b; b=t;}while(0)typedef struct Heap{ int* arr; size_t cal原创 2021-08-05 20:39:43 · 60 阅读 · 0 评论 -
【数据结构与算法】有序二叉树(左<根<=右)的功能实现
#include <stdio.h>#include <stdlib.h>#include <stdbool.h>//创建结构体typedef struct TreeNode{ int data; struct TreeNode* left; struct TreeNode* right;}TreeNode;//创建树结点TreeNode* create_node(int data){ TreeNode* node = malloc(sizeof原创 2021-08-04 18:56:33 · 94 阅读 · 0 评论 -
【数据结构与算法】二叉树的顺序存储
#include <stdio.h>#include <stdlib.h>#include <stdbool.h>#include <string.h>#include <math.h>//创建结构体typedef struct TreeArray{ char* arr; size_t cal;}TreeArray;//创建TreeArray* create_tree(char* level_str){ TreeArra原创 2021-08-03 20:19:43 · 113 阅读 · 0 评论 -
【数据结构与算法】链式结构的二叉树,通过前序和中序来创建树
#include <stdio.h>#include <stdlib.h>#include <stdbool.h>#include "queue.h"//构造树结点typedef struct TreeNode{ char data; struct TreeNode* left; struct TreeNode* right;}TreeNode;//创建结点TreeNode* create_tree_node(char data){ TreeN原创 2021-08-02 19:07:40 · 72 阅读 · 0 评论 -
【数据结构与算法】双向通用链表的功能实现
.h文件#ifndef LIST_H#define LIST_H#include <stdio.h>#include <stdbool.h>#define swap(a,b) {typeof(a) t=a; a=b; b=t;}typedef struct Node{ void* data; struct Node* prev; struct Node* next;}Node;typedef struct List{ Node* head; siz原创 2021-07-30 09:04:45 · 101 阅读 · 0 评论 -
【数据结构与算法】用带头节点的方式来实现链表功能
在链表初创之时,并没有自建一个无意义的头结点,但随着发现创建了“无意义”的头结点之后整个代码简谐了,但在应试中大家还是要求自主实现不带头结点的链表功能。可以对比下有头结点和无头结点代码的美观性和可读性,附上无头结点的代码:https://blog.csdn.net/weixin_54057383/article/details/119151365#include <stdio.h>#include <stdlib.h>#include <stdbool.h>#原创 2021-07-28 19:39:14 · 89 阅读 · 0 评论 -
【数据结构与算法】用二级指针实现链表的功能
#include <stdio.h>#include <stdlib.h>#include <stdbool.h>#define TYPE inttypedef struct Node{ TYPE data;//数据域 struct Node* next;//指针域}Node;//创建结点Node* create_node(TYPE data){ Node* node = malloc(sizeof(Node)); node->data原创 2021-07-27 19:23:57 · 192 阅读 · 0 评论