
数据结构
最后冰吻free
不在沉默中死亡,就在沉默中爆发
展开
-
二分查找法
【代码】二分查找法。原创 2023-09-24 13:48:16 · 163 阅读 · 0 评论 -
腐烂橘子图问题
【代码】腐烂橘子图问题。原创 2023-09-23 23:45:35 · 174 阅读 · 0 评论 -
和为k的子数组个数
【代码】和为k的子数组个数。原创 2023-09-17 00:01:09 · 136 阅读 · 0 评论 -
所有字母异位词
【代码】所有字母异位词。原创 2023-09-16 21:37:31 · 148 阅读 · 0 评论 -
三数之和 数组
【代码】三数之和 数组。原创 2023-09-16 18:48:27 · 132 阅读 · 0 评论 -
环形链表的入口节点
【代码】环形链表的入口节点。原创 2023-09-10 00:17:46 · 246 阅读 · 0 评论 -
和并两个有序链表
【代码】和并两个有序链表。原创 2023-09-02 18:41:25 · 97 阅读 · 0 评论 -
linux C选择排序
#include <stdio.h>#include <time.h>void bubble_print(int array[], int len);#define MAX_NUM 10int select_sort(int array[], int len) { int i = 0; int j = 0; int temp = 0; //组循环 for (i = 0; i < len -1; i++)原创 2020-10-13 21:48:24 · 193 阅读 · 0 评论 -
单向链表的倒置
void list1n_listn1(linkP H){ linkP p = H->next;//第一个节点 H->next = NULL;//仅含有头节点 linkP q; while(p) { q = p;// q为p的复制,p用于遍历 p = p->next; q->next = H->next;// 奖原创 2016-03-17 19:53:48 · 512 阅读 · 0 评论 -
最大公约数
#include <iostream>/** 1.穷举法,确定大小值,用最大最小值对i(有minx到1)进行取模, * 循环n/2-1,时间复杂度O(n) */int GetMaxCommonDivisor(int a, int b){ int i = 0; int max = a >= b ? a : b; int min = a < b ? a : b; if (max % min == 0) return min;原创 2021-12-06 23:13:27 · 574 阅读 · 0 评论 -
环形链表判断
typedef struct Node{ int data; struct Node *next;} STNode;// 检查给出的链表是否为环形链表, p1步长为1,p2步长为2,若p1==p2则说明为环形(追急问题)int isCicleList(STNode *root){ STNode *p1 = root; STNode *p2 = root; while (p1 != NULL && p2->next != NULL)原创 2021-12-04 22:24:48 · 492 阅读 · 0 评论 -
鸡尾酒排序
#include <stdio.h>/** 鸡尾酒排序:若待排序数组为{2,3,4,5,6,7,8,1},发现2-8是有序的, * 只因为1需要进行7轮排序比较,鸡尾酒排序可以解决这种问题, * 以先从左排序,再右排序(类似钟摆)*/int CocktaiSort(int *array, int len){ if (array == NULL) return -1; int i = 0; int j = 0; int temp = 0;原创 2021-11-27 18:00:01 · 411 阅读 · 0 评论 -
计数排序算法
#include <stdio.h>#include <stdlib.h>#define ELEMENT_COUNT 10// 计数排序int RadixSort(int *array, int len){ int i = 0; int j = 0; if (array == NULL) { return -1; } // 默认第一个位最大值,遍历数组找出最大值 int max = array[0]原创 2021-11-26 21:57:17 · 492 阅读 · 0 评论 -
动态规划
有一座高度是10级台阶的楼梯,从下往上走,每跨一步只能向上1级或者2级台阶。要求用程序来求出一共有多少种走法。#include <stdio.h>/* 动态规划:分阶段求解,大事化小,小事化了,由最优子结构,边界和状态转换公式组成; 假设0-9共有x种,第9层到第10层,1 假设0-8共有y种,第8层到第10层,1 1 或2, 则到第10层F(10)=F(9)+F(8)//最优子结构*/int get_all_num(int n){ if (n == 1) return 1;原创 2021-05-21 23:17:43 · 101 阅读 · 0 评论 -
单向链表逆序
//输入一个链表,反转链表后,输出新链表的表头。 ListNode* ReverseList(ListNode* pHead) { if (pHead == NULL) return NULL; ListNode* pre = NULL; ListNode* cur = pHead; //保存当前节点,用于循环 ListNode* pnext = pHead->next;//保存当前节点下一个节点 wh原创 2021-05-20 23:44:09 · 161 阅读 · 0 评论 -
二叉树递归遍历实现
#include <stdio.h>#include <stdlib.h>typedef int KEY_VALUE;struct bstree_node_st{ KEY_VALUE data; struct bstree_node_st *left; struct bstree_node_st *right;};struct bstree_st{ struct bstree_node_st *node;};struct b原创 2021-03-18 17:39:34 · 99 阅读 · 0 评论 -
数据结构 二叉树遍历
#include <stdio.h>#include "link_stack.h"/* *二叉树非递归实现:链式栈的应用*/#define BT_TRUE 1#define BT_FALSE 0//每个节点:存放数据,有左右孩子(没有孩子,为NULL)typedef struct BinTree{ char ch; struct BinTree* lchild; struct BinTree* rchild;}STBinTree_def;//自定义数据,每原创 2020-10-09 18:21:41 · 188 阅读 · 0 评论 -
数据结构 栈的应用(括号匹配)
#include <stdio.h>#include <stdlib.h>#include <string.h>//链式栈:括号匹配校验#define SUCCESS 0#define FAILURE 1typedef struct Node{ struct Node *next;}STNode_def;typedef struct LinkStack{ struct Node head; int size;}STLinkStack_原创 2020-09-23 14:48:25 · 249 阅读 · 0 评论 -
数据结构 约瑟夫环问题
#include <stdio.h>#include <stdlib.h>/***企业链表,与常规链表不同是,链表数据类型和链表进行分离(解耦)*当业务发生变化,需要新的数据类型时,不需要写新的链表*///与自定义数据类型node进行对应typedef struct Node{ struct Node *next;}STNode_def;//链表头结点typedef struct CicLinklist{ struct Node head; int si原创 2020-09-23 09:59:32 · 416 阅读 · 0 评论 -
数据结构 队列
#include <stdio.h>#include <stdlib.h>#include <string.h>//链式栈:使用企业式链表存储元素#define SUCCESS 0#define FAILURE 1typedef struct Node{ struct Node *next;}STNode_def;typedef struct LinkQueue{ struct Node head; int size;}STLinkQ原创 2020-09-22 13:46:20 · 131 阅读 · 0 评论 -
数据结构 顺序栈和企业链式栈
#include <stdio.h>#include <stdlib.h>#include <string.h>//顺序栈:元素存储在连续的内存空间,类似数组#define STACK_NUM 20#define SUCCESS 0#define FAILURE 1typedef struct Stack{ void* data[STACK_NUM]; int size;}STStack_def;typedef void (*STACK原创 2020-09-22 11:01:21 · 125 阅读 · 0 评论 -
数据结构 普通链表、企业链表和循环链表
//普通有头结点链表#include <stdio.h>#include <stdlib.h>#include <string.h>//有头结点的单向链表typedef struct MyNode{ int num; struct MyNode *next;}STNode_def;#define NODE_SIZE sizeof(STNode_def)#define SUCCESS 0#define FAILURE -1//链表原创 2020-09-18 13:51:05 · 251 阅读 · 0 评论 -
数据结构 动态数组
#include <stdio.h>#include <string.h>#include <stdlib.h>#define FAILURE -1#define SUCCESS 0typedef struct{ int *array_ptr; //数组指针 int size; //元素个数 int capacity; //容量大小}Array_def;//初始化Array_def*原创 2020-09-16 15:21:08 · 135 阅读 · 0 评论