- 博客(81)
- 资源 (4)
- 收藏
- 关注
原创 C语言 散列表 分离链接法
运行结果正确怎么说呢,散列表最重要的还是怎么设计散列函数,解决冲突还是很简单的完整代码#include<stdio.h>#include<malloc.h>#include<stdlib.h> //定义链表 typedef struct list_node *list_point ; struct list_node{ int val; list_point next; }; //定义散列表 typedef struct table_nod
2021-06-03 14:06:26
370
1
原创 C语言 桶排序
运行结果正确完整代码#include<stdio.h>#include <stdlib.h>#include <string.h>#include<malloc.h>void simple_bucket_sort(int arr[],int n,int max);void tra_arr(int arr[],int n);int main(){ int arr[10]={ 10,9,9,9,5,5,5,1,1,1 }; simple
2021-06-02 19:31:01
265
1
原创 C语言 基数排序
运行结果正确完整代码(审核中)主要代码#include"队列声明.h"void tra_arr(int arr[],int n);void get_pos_value(int in,int pos,int &result);void base_sort(int arr[],int n,int pos_num);int main(){ int arr[10]={ 999,888,777,66,55,44,3,2,1,33 }; base_sort(arr,10,3);
2021-06-02 19:23:37
288
1
原创 C语言 所有排序方法的实现
运行结果正确还是快速排序难一些。完整代码#include<stdio.h>#include <stdlib.h>#include <string.h>#include<malloc.h>void swap(int *a,int *b);void select_sort(int arr[],int n);void tra_arr(int arr[],int n);void insert_sort(int arr[],int n); voi
2021-05-30 20:05:05
737
10
原创 C语言 关键路径计算
运行结果正确完整代码还在审核主要代码#include"邻接表声明.h"#include"队列声明.h"#include"栈的声明.h"//统计入度void count_degree(adj_g_point g,int degree[]){ //初始化数组 for(int i=0;i<g->v_num;i++){ degree[i]=0; } //开始统计 adj_e_point e; int j; for(int i=0;i<g->v_num;i
2021-05-28 16:05:43
443
原创 C语言 拓扑排序 邻接表实现
运行结果正确完整代码 还在审核主要代码#include"邻接表声明.h"#include"队列声明.h"//拓扑排序void top_sort(adj_g_point g,int result[]){ //首先找一个数组把入度存一下 int *in_degree=(int*)malloc((g->v_num)*sizeof(int)); //初始化这个入度表 for(int i=0;i<g->v_num;i++){ in_degree[i]=0;
2021-05-27 17:10:01
484
原创 C语言 最小生成树 prim算法
运行结果正确主程序#include"矩阵声明.h"#include"邻接表声明.h"//在没访问过的顶点中找到与当前树距离最近的顶点void find_min(mat_g_point g,int dist[],int &min_id){ //首先给一个最大值去比较 int min=1000; //对每个顶点进行遍历 for(int i=0;i<g->nv;i++){ //如果没访问过,且权值比当前还要小 if(dist[i]!=0&&dist[
2021-05-26 15:54:17
397
原创 C语言 多源最短路径 邻接矩阵
运行结果正确输出路径顶点竟然花了我最多的时间。。。。。。#include<stdio.h>#include <stdlib.h>#include <string.h>#include<malloc.h>//邻接矩阵表示图typedef struct g_node *g_point;struct g_node{ int ne;//边数 int nv;//节点数 int arr[100][100]; int data[100];};
2021-05-18 16:06:20
318
原创 C语言 单源最短路径 有权 邻接矩阵
运行结果正确注意初始化的时候对path的特殊处理#include<stdio.h>#include <stdlib.h>#include <string.h>#include<malloc.h>//邻接矩阵表示图typedef struct g_node *g_point;struct g_node{ int ne;//边数 int nv;//节点数 int arr[100][100]; int data[100];};//边
2021-05-18 13:59:28
374
原创 C语言 完全二叉搜索树
运行结果正确其实计算树高那个地方我不是很懂为什么要/log(2)。#include <stdio.h>#include <stdlib.h>#include <math.h>//求左子树的节点数void left_tree_total(int n,int &total){ //首先,算一下完美二叉树的树高 int h=(int)floor(log(n+1)/log(2)); //计算完全二叉树的最后一层的叶子节点数 int x=n-pow(
2021-05-17 11:05:45
336
原创 C语言 前序和中序遍历确定后序遍历
运行结果正确还是很讨厌递归#include <stdio.h>#include <stdlib.h>int pre[100];//先序遍历数组 int in[100];//中序遍历 数组 int post[100]={0};//后序遍历数组 //后序遍历结果void tra_post(int total){ for(int i=0;i<total;i++){ printf("%d ",post[i]); } printf("\n");} //由先
2021-05-16 21:46:55
1078
原创 C语言 深度优先搜索 非递归
运行结果正确注意,实际上栈里面存的是经过的节点#include<stdio.h>#include <stdlib.h>#include <string.h>#include<malloc.h>//创建邻接表//这个边的数据结构是用来给我们输入使用的typedef struct se_node *se_point;struct se_node{ int v1,v2; int weight;} ;//创建邻接表的边 typedef s
2021-05-16 14:24:35
684
原创 C语言 邻接表 广度优先搜索 非递归
运行结果正确非递归虽然实现起来比较复杂,但是容易纠错,也更好理解#include<stdio.h>#include <stdlib.h>#include <string.h>#include<malloc.h>//创建邻接表//这个边的数据结构是用来给我们输入使用的typedef struct se_node *se_point;struct se_node{ int v1,v2; int weight;} ;//创建邻接表的边
2021-05-15 23:45:13
570
原创 C语言 邻接表表示无向图
运行结果正确用邻接表来表示图要创造的结构体太多了,我感觉其实有更简单的结构体来表示图。#include<stdio.h>#include <stdlib.h>#include <string.h>#include<malloc.h>//创建邻接表//这个边的数据结构是用来给我们输入使用的typedef struct se_node *se_point;struct se_node{ int v1,v2; int weight;} ;
2021-05-15 13:19:16
1140
原创 C语言 邻接矩阵表示无向图
运行结果正确#include<stdio.h>#include <stdlib.h>#include <string.h>#include<malloc.h>//邻接矩阵表示图typedef struct g_node *g_point;struct g_node{ int ne;//边数 int nv;//节点数 int arr[100][100]; int data[100];};//边的数据结构typedef struc
2021-05-15 09:38:49
773
1
原创 c语言 集合 按秩归并 压缩路径
运行结果正确感觉比二叉树还简单#include<stdio.h>#include <stdlib.h>#include <string.h>#include<malloc.h>//先定义一个栈 typedef struct Stack{ int base[100]; int top; }stack,*stack_point; //初始化一个集合的数组,数组的下标就是集合的元素,数组的值就是这个元素的父节点 void
2021-05-13 17:07:16
163
原创 c语言 赫夫曼树和编码(哈夫曼树和编码)
运行结果正确感觉最难的是树的合并#include<stdio.h>#include <stdlib.h>#include <string.h>#include<malloc.h>//构造哈夫曼树typedef struct { int val; int parent,left,right;}node,*tree;//构造哈夫曼编码typedef struct{ int weight; int code[10];}code_nod
2021-05-11 21:58:16
445
原创 C语言 建堆
运行结果正确实际上,建堆和删除堆是一样的。#include<stdio.h>#include <stdlib.h>#include <string.h>#include<malloc.h>//构造结构堆typedef struct node *heap;struct node { //这是一个数组 int *base; int max; int size;};//遍历这个堆void tra(heap h){ for(int
2021-05-10 14:12:12
246
1
原创 C语言 堆的插入与删除
运行结果正确感觉堆还是比二叉搜索树容易实现#include<stdio.h>#include <stdlib.h>#include <string.h>#include<malloc.h>//构造结构堆typedef struct node *heap;struct node { //这是一个数组 int *base; int max; int size;};//遍历这个堆void tra(heap h){ for(int
2021-05-10 13:17:14
381
原创 c语言 是否同一颗二叉搜索树
运行结果正确#include<stdio.h>#include <stdlib.h>#include <string.h>#include<malloc.h>//构造结构树typedef struct node *tree;struct node{ int val; int flag; tree left; tree right;};//遍历void pre_tra(tree t){ tree t1=t; if(t1==NUL
2021-05-09 20:36:50
276
2
原创 c语言 判断二叉树是否同构
运行结果正确链式静态数组相比于指针要考虑的东西少很多1.同构的例子2.不同构的例子#include<stdio.h>struct tree{ char val; int left; int right;}t1[100],t2[100];//构建树int creat(struct tree t[]){ int total,root; char ch,rc,lc; printf("输入树节点总数\n"); scanf("%d",&total); ch=ge
2021-05-09 13:33:03
1259
原创 C语言 二叉查找树的插入与删除
运行结果正确。讨厌递归。#include"stdio.h"#include"stdlib.h"typedef struct Tree_node{ int val; struct Tree_node *pare; struct Tree_node *left; struct Tree_node *right;}node,*tree;//创造节点node* creat_node(int val,node *pare,node *left,node *right){ node *n;
2021-05-08 18:48:38
295
原创 c语言 树的层序遍历
运行结果正确层序遍历比先序递归和非递归都要简单。#include <stdio.h>#include <stdlib.h>typedef struct tree_node{ int val; struct tree_node *left; struct tree_node *right;}tree,*tree_point;//创建新树int creat_tree(tree **t){ int val; scanf("%d",&val); if(
2021-05-05 20:07:50
986
原创 c语言 非递归遍历二叉树
运行结果正确其实也不难,牢牢记住栈是用来放右节点的就行了。#include <stdio.h>#include <stdlib.h>typedef struct tree_node{ int val; struct tree_node *left; struct tree_node *right;}tree;//top是为非递归的栈提供的 int top=-1;//创建新树int creat_tree(tree **t){ int val; scan
2021-05-05 16:57:58
534
原创 C语言 多项式相加和相乘
成功运行,结果完美,但是不知道为什么要用二级指针。#include<stdio.h>#include<stdlib.h> //多项式的加法和乘法typedef struct Poly_node *poly_list; struct Poly_node{ int coe; int ind; poly_list next;};//插入结果尾部 int insert(int coe,int ind,poly_list *rear){ poly_list t=(pol
2021-05-03 14:29:45
783
原创 C语言中缀转后缀
太多情况要考虑了(超级多if),实际上写起来很繁琐。#include <stdio.h>#include <stdlib.h>//数据总栈typedef struct Gen{ char elem[200]; int top;}gen;// 符号总栈typedef struct Sym{ char elem[200]; int top;} sym;//初始化int init(gen *g,sym *s){ g->top=-1; s->top
2021-05-03 11:33:41
135
原创 C语言 栈实现进制转换
#include <stdio.h>#include <malloc.h>#include <stdlib.h>typedef struct{ int data[100]; int top;}stack;//初始化 stack* init(){ stack *s; s=(stack*)malloc(sizeof(stack)); s->top=0; return s;}//压栈stack* push(stack *s,int val){
2021-05-02 15:16:38
196
原创 c语言 实现双向链表
原文地址运行结果正确#include <stdio.h>#include <stdlib.h>typedef struct line { struct line * prior; int data; struct line * next;}line;line* initLine(line * head) { int i = 0; line * list = NULL; head = (line*)malloc(sizeof.
2021-05-02 13:25:58
56
原创 c语言 实现循环链表
原文地址挺厉害的,没有错误#include <stdio.h>#include <stdlib.h>#define TRUE 1#define FALSE 0typedef int Status; // Status是函数结果状态,成功返回TRUE,失败返回FALSEtypedef int ElemType;/* 线性表的循环链表存储结构 */typedef struct node{ ElemType data; struct node *next;}
2021-05-01 23:04:21
651
原创 C语言 数组实现循环队列
虽然实现了,但实际上并不需要每次都取余,可以自己去优化。#include<stdio.h>#include<malloc.h>#include<stdlib.h>//循环队列#define MAX 5typedef struct Loop_que{ int base[MAX]; int rear; int size; int front;}loop;//初始化loop* init(){ loop *l=(loop*)malloc(sizeof(
2021-05-01 14:35:47
302
原创 C语言 数组实现队列
代码不健全,但是能实现#include<stdio.h>#include<malloc.h>#include<stdlib.h>//数组实现队列typedef struct Que{ int a[100]; int front; int rear;} que;//初始化que * init(que *q){ q=(que*)malloc(sizeof(que)); q->front=q->rear=0; return q;
2021-05-01 12:33:46
678
原创 c语言 链表实现队列
健全性很差,但是实现没问题。自己可以去补#include<stdio.h>#include<malloc.h>#include<stdlib.h>//链表节点 typedef struct Link{ int val; struct Link *next;}link;//队列 typedef struct Que{ struct Link *front,*rear;}que;//初始化 void init(que *q){ q->fro
2021-04-30 22:00:11
154
1
原创 c语言 链表实现堆栈
不知道怎么得到栈顶指针#include <stdio.h>#include <stdlib.h>typedef struct Stack{ int elem; struct Stack *next;}stack;//初始化stack* init(){ stack *s=(stack*)malloc(sizeof(stack)); s->elem=NULL; s->next=NULL; return s;} //压栈stack* push(st
2021-04-30 16:01:51
71
1
原创 C语言 数组实现堆栈
虽然能遍历,但是会清空栈#include <stdio.h>#include <malloc.h>#include <stdlib.h>typedef struct{ int data[100]; int top;}stack;//初始化 stack* init(){ stack *s; s=(stack*)malloc(sizeof(stack)); s->top=0; return s;}//压栈stack* push(stack
2021-04-30 15:17:29
309
1
原创 链表实现顺序储存(c语言)
1.插入删除第一个位置总是有问题,但不知道怎么解决。。。。2.指针好香啊#include <stdio.h>#include <stdlib.h>//链表中节点的结构typedef struct Linklist{ int elem; struct Linklist *next;}linklist;//初始化链表linklist* init(){ linklist *p=NULL;//创建头指针 linklist * temp=(linklist*)mal
2021-04-30 11:09:40
357
2
原创 c语言 数组实现 线性表的顺序储存
#include <stdio.h>#include <malloc.h>#include <stdlib.h> struct list{ int* arr; //数组首元素地址 int max; //数组总长度 int last; //数组当前元素个数}; //数组初始化void init_list(struct list * l, int max){ l->arr = (int*
2021-04-29 16:23:24
195
原创 8.mybatis 一对多的实现
1.沿用之前的两张表明显,一个User可以有多个orders2需求根据user.name='王五’查orders3.在数据库中写出来SELECT u.`username` u_name, o.id o_id FROM orders o,USER uWHERE o.`user_id`=u.`id`AND u.`username`='王五';4.创建两个model user_2 ,orders(和前面不一样)(1)user(将orders包装进来)public class Us
2020-08-30 21:24:42
172
原创 7.mybatis一对一关系的实现
1.首先创建两张表(自己插入数据)虽然这两张表的关系明显是一对多,但是我们这里可以使用他们演示一对一,毕竟一对一只是一对多的特例罢了2.需求根据订单id=3查询用户名3.在数据库实现查询SELECT o.id o_id ,u.`username` u_nameFROM orders o,USER uWHERE o.`user_id`=u.`id` AND o.`id`=3;4.建两个model,ordes,user_2,对应两张表(1)user_2public class
2020-08-30 21:24:03
138
原创 6.mybatis resultMap标签的使用
1.使用场景:当model类的属性名和数据库的表头名对不上时2.创建一个新modelpublic class User_1 { private String _name; private String _password; public String get_name() { return _name; } public void set_name(String _name) { this._name = _name;
2020-08-30 21:23:28
136
原创 5.mybatis 传递map对象
1.目录结构2.userMapperpublic List<User> find_by_map(Map<String,String> map);3.use.xml <select id="find_by_map" parameterType="hashmap" resultType="user"> select * from user where name=#{name} </select>4.test Has
2020-08-30 21:23:04
633
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人