- 博客(18)
- 收藏
- 关注
原创 数据结构——N皇后问题
总结:在一个N*N的棋盘上放置N个皇后,每行一个并使其不能互相攻击(同一行、同一列、同一斜线上的皇后都会自动攻击)。 回溯算法也叫试探法,它是一种系统地搜索问题的解的方法。 回溯算法的基本思想是:从一条路往前走,能进则进,不能进则退回来,换一条路再试.总代码:#include <stdio.h>#include <malloc.h>#include <math.h> /** * Place it there, applicable? */bool
2022-05-29 18:38:50 182
原创 数据结构 C 代码12:哈夫曼树
总结:哈夫曼树的作用就是合理的设定这些结点的位置关系,使得权值越高的结点所经历的的路径越短。总代码#include <iostream>#include <fstream>#include <string.h>using namespace std; #define MaxSize 1024 // 读入文件的上限 #define OK 1#define ERROR 0typedef int Status; typedef struct w
2022-05-29 18:33:41 330
原创 数据结构,二叉树及其遍历
总代码#include <stdio.h>#include <malloc.h>#include <stdbool.h>#define MAXSIZE 5//对于二叉树,我们一般都是用链式存储,顺序存储的话会造成很多空间的浪费 typedef struct BTNode{ char element; struct BTNode *left; struct BTNode *right;}*BTNodePtr;//这里队列就用的是顺序循环存储
2022-05-24 18:43:18 92 1
原创 二维数组与矩阵乘法和压缩矩阵的转置
一.二维数组与矩阵乘法1.二维数组简单讲就是:数组元素是数组的数组数组grades的每一个元素都是数组。相当于构建了一个3x3的数据表格2.矩阵乘法矩阵乘法是一种高效的算法可以把一些一维递推优化到log(n),还可以求路径方案等,所以更是一种应用性极强的算法。必须注意的是,只有当矩阵A的列数与矩阵B的行数相等时A×B才有意义。一般单说矩阵乘积时,指的便是一般矩阵乘积。若A为m×n矩阵,B为n×p矩阵,则他们的乘积AB(有时记做A·B)会是一个m×p矩阵。总代码#include &
2022-05-19 20:35:47 105
原创 链队列和循环队列 数据结构C语言
链队列:总代码#include<stdio.h>#include<malloc.h> typedef struct node { int data; struct node* next;}*NodePtr, Node; typedef struct { NodePtr front, rear;}LinkQue, * LinkQuePtr; LinkQuePtr Init() { NodePtr q = (NodePtr)malloc(sizeof(
2022-05-17 15:42:52 127
原创 汉诺塔 C语言
总代码#include <stdio.h>/** * Hanoi. */void hanoi(int paraN, char paraSource, char paraDestination, char paraTransit) { if (paraN <= 0) { return; } else { hanoi(paraN-1, paraSource, paraTransit, paraDestination);//将 n - 1个盘从S 通过D 移动到 T
2022-05-12 15:40:22 113
原创 累加的递归实现 C语言
总代码#include <stdio.h>#include <stdlib.h>int tot=0;void addto(int number){ if (number <= 0){ printf("Final:total=%d\n",tot); tot=0; } else{ printf("Now total: %d=%d+%d\n",tot+number,tot,number); tot=tot+nu
2022-05-12 15:35:13 794
原创 栈 括号匹配 C语言
这是对栈的一种运用,可以帮助我们对栈理解更加透彻,深入了解栈总代码#include <stdio.h>#include <malloc.h> #define STACK_MAX_SIZE 10 /** * Linear stack of integers. The key is data. */typedef struct CharStack { int top; int data[STACK_MAX_SIZE]; //The maxim
2022-05-10 19:12:41 226
原创 栈 C语言
栈(stack)又名堆栈,它是一种运算受限的线性表。限定仅在表尾进行插入和删除操作的线性表。这一端被称为栈顶,相对地,把另一端称为栈底。向一个栈插入新元素又称作进栈、入栈或压栈,它是把新元素放到栈顶元素的上面,使之成为新的栈顶元素;从一个栈删除元素又称作出栈或退栈,它是把栈顶元素删除掉,使其相邻的元素成为新的栈顶元素。栈的特殊之处在于:仅在表尾进行插入和删除操作的线性表。也就是先进后出,只有后入的数据出栈,之前的数据才能出栈。空栈:不含任何数据元素的栈。允许插入和删除的一端称为栈顶,另一端称为栈底。
2022-05-10 19:06:20 293
原创 栈表达式求值 c语言
总代码#include <iostream>#include <stdio.h>//定义常量 #define OK 1#define ERROR 0#define TRUE 1#define FALSE 0#define MAXSIZE 100#define OVERFLOW -2//个性化设置using namespace std;typedef char SElemType;typedef int NElemType;typedef int S
2022-05-10 19:00:41 483
原创 多项式加法 C语言
完整代码#include<stdio.h>#include<malloc.h>/** *Linked list of integers. The key is data. The key is sorted in non-descending order. */typedef struct LinkNode{ int coefficient; int exponent; struct LinkNode *next;}*LinkList, *NodePtr;
2022-05-06 09:33:34 324 1
原创 静态链表 C语言
总函数#include <stdio.h>#include <malloc.h>#define DEFAULT_SIZE 5typedef struct StaticLinkedNode{ char data; int next;} *NodePtr;typedef struct StaticLinkedList{ NodePtr nodes; int* used;} *ListPtr;/** * Initialize the list wit
2022-05-03 15:27:34 60
原创 双链表 C语言
总代码:#include <stdio.h>#include <malloc.h>/** * Double linked list of integers. The key is char. */typedef struct DoubleLinkedNode{ char data; struct DoubleLinkedNode *previous; struct DoubleLinkedNode *next;} DLNode, *DLNodePtr;.
2022-05-03 15:22:05 65
原创 数据结构 单链表
1创建链表typedef struct LinkNode{ char data; struct LinkNode *next;} LNode, *LinkList, *NodePtr;2初始化LinkList initLinkList(){ NodePtr tempHeader = (NodePtr)malloc(sizeof(LNode)); tempHeader->data = '\0'; tempHeader->next = NULL; return t
2022-04-29 12:01:30 69
原创 c语言:顺序表
#include <stdio.h>#include <malloc.h>#define LIST_MAX_LENGTH 10/** * Linear list of integers. The key is data. */typedef struct SequentialList { int actualLength; int data[LIST_MAX_LENGTH]; //The maximum length is fixed.} *Se.
2022-04-26 09:16:59 76
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人