数据结构
hu的小金库
正在编程路上走
展开
-
冒泡算法+选择算法
void BubbleSort(int arr[], int n){ for(int i = 0; i < n - 1; i++) { for(int j = 0; j < n - i - 1; j++) { if(arr[j] > arr[j+1]) std::swap(arr[j],arr[j+1]); } }}void select_sort(int.原创 2020-11-30 23:10:53 · 92 阅读 · 0 评论 -
最短路迪杰斯特拉算法
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;/** 单源最短路径,Dijkstra 算法,邻接矩阵形式,复杂度为O(n^2)* 求出源beg 到所有点的最短路径,传入图的顶点数,和邻接矩阵cost[][]* 返回各点的最短路径lowcost[], 路径pre[].pre[i] 记录beg 到i 路径上.原创 2020-11-30 22:48:02 · 399 阅读 · 0 评论 -
prim算法----Kruskal一般不考
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 110;const int MAX = 0x3f3f3f3f;int mp[maxn][maxn];int cost[maxn];int n, m;int prim(int n){ int v[maxn]; mem.原创 2020-11-30 21:07:24 · 114 阅读 · 0 评论 -
数据结构书上可运行代码-快排
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <map>#include <algorithm>using namespace std;int Partition(int L[],int low,int high){ int pivotkey = L[low]; int i = low;.原创 2020-11-30 20:55:18 · 217 阅读 · 0 评论 -
平衡二叉树+图片讲解
struct node *LL(struct node *root){ struct node *a = root; struct node *b = root->left; a->left = b->right; b->right = a; a->high = max(height(a->left), heigh...原创 2018-08-20 19:59:57 · 233 阅读 · 0 评论 -
数据结构书上的代码堆排序-小顶堆
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <map>#include <algorithm>using namespace std;const int maxn = 2100;int a[20];void heapadjust(int a[], int l, int r){ int x = a.原创 2020-11-30 15:58:11 · 86 阅读 · 0 评论 -
字符串KMP以及暴力求解
#include <iostream>#include <string.h>using namespace std;int net[100];int lens;int lenp;int Index(char S[],char P[])//朴素的串匹配算法,即暴力求解;{//返回子串P 在主串S 中的位置 int i = 1; int j = 1; // i 和j 也可能从0 开始,依赖于存储设计 while (i <= lens &am.原创 2020-11-28 23:00:08 · 53 阅读 · 0 评论 -
3.3循环队列——队列的顺序表示和实现
#include <iostream>using namespace std;// -----循环队列一队列 的顺序存储结构-----# define MAXQSIZE 100//最大队列长度typedef struct{ int *base; //初始化的动态分配存储空间 int front ; //头指针,若队列不空,指向队列头元素 int rear ; //尾指针,若队列不空,指向队列尾元素的下一个位置} SqQueue;// -----循环队.原创 2020-07-31 18:46:34 · 164 阅读 · 0 评论 -
3.2数据结构书上可运行代码——队列
#include <iostream>using namespace std;//#define STACK_INIT_SIZE 100 //存储空间初始分配量//#define STACKINCREMENT 10 //存储空间分配增量const int STACK_INIT_SIZE = 100;const int STACKINCREMENT = 10;//-----单链队列一队列 的链式存储结构-----typedef struct QNode{ int dat.原创 2020-07-31 18:16:49 · 138 阅读 · 0 评论 -
3.1栈与队列的基本操作+应用一:数制转换
#include <iostream>using namespace std;//#define STACK_INIT_SIZE 100 //存储空间初始分配量//#define STACKINCREMENT 10 //存储空间分配增量const int STACK_INIT_SIZE = 100;const int STACKINCREMENT = 10;typedef struct{ int *base; int *top; int stacksiz.原创 2020-07-31 16:39:12 · 237 阅读 · 0 评论 -
栈与队列应用二:括号匹配
roblem Description给你一串字符,不超过50个字符,可能包括括号、数字、字母、标点符号、空格,你的任务是检查这一串字符中的( ) ,[ ],{ }是否匹配。Input输入数据有多组,处理到文件结束。Output如果匹配就输出“yes”,不匹配输出“no”Sample Inputsin(20+10){[}]Sample Outputyesno#include<stdio.h>#include<s...原创 2020-07-31 16:35:33 · 287 阅读 · 0 评论 -
2.2链表-约瑟夫环问题-两种解决思想
课件代码:#include<iostream>using namespace std;#include <stdio.h>#include <stdlib.h>typedef struct node{ int No; /*游戏者的编号*/ int Pwd; /*游戏者的密码*/ struct node *next;}LNode,*LinkList;LinkList create_lis.原创 2020-07-30 17:44:11 · 180 阅读 · 0 评论 -
1.数据结构书上可运行代码--线性表的顺序表示和实现
#include <iostream>using namespace std;#define INIT_SIZE 100 //空间初始分配量#define INCREMENT 10 //增量typedef struct node1//静态分配{ int elem[INIT_SIZE]; int length;};typedef struct node2//动态分配{ int *elem; //存储空间基址 int length; //当前长度.原创 2020-07-30 14:04:43 · 141 阅读 · 0 评论 -
2.1数据结构书上可运行代码--线性表的链式表示和实现
#include <iostream>using namespace std;typedef struct node{ int data; struct node *next;} LNode, *LinkList;int GetElem_L(LinkList L, int i, int &e)//查找第i个元素{ LinkList p; p=L->next; int j=1; while(p&&j<.原创 2020-07-30 11:10:03 · 176 阅读 · 0 评论