- 博客(15)
- 收藏
- 关注
原创 数据结构----邻接表及广度优先遍历
图的表示:邻接表邻接表结构原理在邻接列表实现中,每一个顶点会存储一个从它这里开始的相邻边的列表。比如,如果顶点 B 有一条边到 A、C 和 E,那么 A 的列表中会有 3 条边。邻接列表只描述指向外部的边。B 有一条边到 A,但是 A 没有边到 B,所以 B 没有出现在 A 的邻接列表中。查找两个顶点之间的边或者权重会比较费时,因为遍历邻接列表直到找到为止。完整代码/*Adjacency list for directed graph.author Fan Min minf.
2022-05-31 18:41:48
259
原创 数据结构----图的遍历
图的遍历图的遍历是指,从给定图中任意指定的顶点(称为初始点)出发,按照某种搜索方法沿着图的边访问图中的所有顶点,使每个顶点仅被访问一次,这个过程称为图的遍历。完整代码#include<stdio.h>#include<malloc.h>#define QUEUE_SIZE 10int* visitedPtr;/*A queue with a number of indices.*/typedef struct GraphNodeQueue{ int
2022-05-31 17:19:45
321
原创 数据结构----Huffman树
完整代码#include <iostream>#include <fstream>#include <string.h>using namespace std; #define MaxSize 1024 // 读入文件的上限 #define OK 1#define ERROR 0typedef int Status;typedef struct wordcnt{ // 统计字符和对应的次数 char ch; int cnt = 0;}
2022-05-27 21:07:22
115
原创 数据结构----n后问题
完整代码#include<stdio.h>#include<malloc.h>#include<math.h>/*Place it there, applicable?*/bool place(int* paraSolution, int paraT){ int j; for(j=1;j<paraT;j++){ if((abs(paraT-j)==abs(paraSolution[j]-paraSolution[paraT]))||par
2022-05-27 20:29:47
98
原创 数据结构----二叉树
完整代码#include<stdio.h>#include<malloc.h>#define QUEUE_SIZE 5/*Binary tree BTNode.*/typedef struct BTNode{ char element; BTNode* left; BTNode* right;}BTNode, *BTNodePtr;/*A queue with a number of pointers.*/typedef struct BTNo
2022-05-24 18:44:13
90
原创 数据结构----二维数组与矩阵乘法、压缩矩阵的转置
完整代码#include<stdio.h>#include<malloc.h>#include<stdlib.h>#define ROWS 4#define COLUMNS 5/*Two dimensional array.*/typedef struct TwoDArray{ int rows; int columns; int** elements;}TwoDArray,*TwoDArrayPtr;/*Two dimensio
2022-05-19 21:56:40
218
原创 数据结构----链队列、循环队列
完整代码#include<stdio.h>#include<malloc.h>/*链队列的节点*/typedef struct LinkNode{ int data; LinkNode* next;}*LinkNodePtr;/*链队列.*/typedef struct LinkQueue{ LinkNodePtr front; LinkNodePtr rear;}*LinkQueuePtr;/*Construc
2022-05-17 13:53:03
98
原创 数据结构----累加的递归实现、汉诺塔问题
累加递归#include<stdio.h>/*Recursive addition.*/int addTo(int paraN){ int tempSum; printf("entering addTo(%d)\r\n",paraN); if(paraN<=0){ printf("return 0\r\n"); return 0; } else{ tempSum=addTo(paraN-1)+paraN; printf("return %d\r\
2022-05-12 10:52:38
86
原创 数据结构----栈的应用(表达式求值)
老师的代码#include <iostream>#include <cstring>#include <algorithm>#include <stack>#include <unordered_map>using namespace std;stack<int> num;stack<char> op;void eval(){ auto b = num.top(); num.po
2022-05-10 19:47:34
574
原创 数据结构----栈(括号匹配)
一、栈的基本操作栈的基本操作主要有:栈的初始化、判空、判满、取栈顶元素、在栈顶进行插入和删除。在栈顶插入元素称为入栈,在栈顶删除元素称为出栈。二、老师的代码----栈#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
2022-05-10 15:44:39
266
原创 数据结构----多项式相加
老师的代码#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-05 20:51:17
121
原创 数据结构----静态链表
老师的代码#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 with
2022-05-03 14:01:06
74
1
原创 数据结构----双向链表
老师的代码#include<stdio.h>#incude<malloc.h>/*Double linked list of integers.The key is char.*/typedef struct DoubleLinkedNode{ char data; struct DoubleLinkedNode *previous; struct DoubleLinkedNode *next; }DLNode,*DLNodePtr;/*Initial
2022-05-03 13:49:07
80
1
原创 数据结构----单链表
老师的代码#include <stdio.h>#include <malloc.h>/* Linked list of characters. The key is data. */typedef struct LinkNode//结点定义类型{ char data; struct LinkNode *next;} LNode, *LinkList, *NodePtr;//LinkList为结构体指针类型/* Initialize the
2022-04-29 13:25:17
502
原创 数据结构----线性表
线性表基本内容 线性表简称表,是n个元素的有限序列。 特点为每个元素仅有一个前驱和后继,第一个元素无前驱,最后一个元素无后继,并且所有的元素的元素类型相同。 线性表跟其他的逻辑结构的数据一样,存储结构分为顺序储存和链式储存。顺序存储的表称为顺序表,链式存储的称为链表。代码#include <stdio.h>#include <malloc.h>#define LIST_MAX_LENGTH 10/** * Li...
2022-04-25 19:40:09
518
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人