C++
文章平均质量分 68
苏格拉没有底q
这个作者很懒,什么都没留下…
展开
-
拓扑排序
事件的发生有先后顺序#include<iostream>#include<string>#include<string.h>using namespace std;#define MaxVertexNum 100 // 图中顶点数目的最大值typedef int VertexType;// 需要设计两种结点结构类型:一是顶点表...原创 2019-11-11 17:50:54 · 120 阅读 · 0 评论 -
迪杰斯特拉算法
#include<iostream>#include<stdio.h>#include<stdlib.h>using namespace std;#define MaxSize 100 // 顶点数目的最大值typedef char VertexType; // 顶点的数据类型typedef int EdgeType; // 整数表示...原创 2019-11-10 15:49:56 · 803 阅读 · 0 评论 -
克鲁斯卡尔算法
克鲁斯卡尔算法思路:将图中边按照权值从小到大排列,然后从最小的边开始扫描,设置一个边的集合来记录,如果该边并入不构成回路的话,则将该边并入当前生成树。直到所有的边都检测完为止。#include<iostream>#include<stdio.h>#include<stdlib.h>using namespace std;#define MaxS...原创 2019-11-08 23:39:03 · 1177 阅读 · 2 评论 -
最小生成树--------Prim
#include<iostream>#include<stdio.h>#include<stdlib.h>using namespace std;#define MaxVertexNum 100 // 顶点数目的最大值typedef char VertexType; // 顶点的数据类型typedef int EdgeType; /...原创 2019-11-07 17:44:38 · 184 阅读 · 0 评论 -
邻接矩阵
#include<iostream>#include<stdio.h>#include<stdlib.h>using namespace std;#define MaxVertexNum 100 // 顶点数目的最大值typedef char VertexType; // 顶点的数据类型typedef int EdgeType; // ...原创 2019-11-07 16:07:00 · 3776 阅读 · 0 评论 -
DFS
#include<iostream>#include<stdio.h>#include<stdlib.h>using namespace std;typedef int VertexType;#define MaxVertexNum 100// 需要设计两种结点结构类型:一是定点表的顶点,二是单链表的结点typedef struct ArcN...原创 2019-11-06 17:14:14 · 136 阅读 · 0 评论 -
BFS
为了简单,ABCD用1234来代替#include<iostream>#include<stdio.h>#include<stdlib.h>using namespace std;typedef int VertexType;#define MaxVertexNum 100// 需要设计两种结点结构类型:一是定点表的顶点,二是单链表的结点...原创 2019-11-05 19:38:46 · 435 阅读 · 0 评论 -
邻接表
c++代码#include<iostream>#include<string>#include<string.h>using namespace std;#define MaxVertexNum 100 // 图中顶点数目的最大值typedef int VertexType;// 需要设计两种结点结构类型:一是定点表的顶点,二是单链表的结...原创 2019-11-04 15:44:51 · 256 阅读 · 0 评论 -
kmp
public static int[] getNextArray(char[] str2) { if (str2.length == 1) { // 如果长度只有1,那么认为规定第一个为-1 return new int[] {-1}; } int []next = new int[str2.length]; next[0] = -1; // 认为规定next数组前...原创 2019-11-03 18:45:43 · 168 阅读 · 0 评论 -
堆排序
import java.util.Arrays;public class HearSort { public static void heapSort(int []arr) { if (arr == null || arr.length < 2) return; for (int i = 0;i < arr.length;++i) { heapInsert(a...原创 2019-11-02 14:52:20 · 120 阅读 · 0 评论 -
线索二叉树
#include<stdio.h>#include<stdlib.h>#include<malloc.h>#include <iostream>using namespace std;//线索化二叉树的算法思想:////1. 按之前构造二叉链表的方法,构造好叉链表,标志位均为0;////2. 选择恰当的遍历方法遍历该二叉链...原创 2019-11-01 19:21:47 · 93 阅读 · 0 评论 -
用固定数组实现队列---C++
用固定数组实现队列队列顾名思义就是排队的队列,像排队一样先进先出这里举个例子#define _CRT_SECURE_NO_WARNINGS#include<iostream>#define max 10using namespace std; class ArrayQueue{public: ArrayQueue(int len) { this-&g...原创 2019-06-03 19:44:10 · 417 阅读 · 0 评论 -
递归实现归并排序---c++
递归形式----归并排序递归主要的实质就在左右排好序的数组如何重排在一起这里要特别注意一点 int left_index = start;//左边数组起始位置计数器 int right_index = start + mid+1;//右边数组起始位置mid+1+start计数器start一定要写,为什么呢?我一开始认为start我传入的时候是0啊,加不加都无所谓啊。但是在递归的过...原创 2019-05-20 19:28:45 · 2675 阅读 · 0 评论 -
桶排序的铺垫
桶排序给定一个数组,求如果排序之后,相邻两数的最大差值,要求时 间复杂度O(N),且要求不能用非基于比较的排序。再次强调一下,空桶的存在只是为了排除差值最大值来自同一桶内,毕竟空桶左右两边的最小值和最大值的差值一定大于设定的桶值大小的。给出c++的#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include &l...原创 2019-05-24 20:11:33 · 97 阅读 · 0 评论 -
递归实现经典快排---JAVA和C++
快速排序先来看看原理下面就开始算法剖析这里给出c++的代码#define _CRT_SElE_NO_WARNINGS#include<iostream>using namespace std; void swap(int arr[], int i, int j){ int temp = arr[i]; arr[i] = arr[j]; arr[j] =...原创 2019-05-21 20:13:30 · 195 阅读 · 0 评论 -
桶排序
桶排序这里其实并不是将数字填入到数组中,只是在数组值上不断++。#define _CRT_SECURE_NO_WARNINGS#include<iostream>#include <limits>#include <algorithm>#include <time.h>#define MAX 20using namespace st...原创 2019-05-26 19:18:37 · 107 阅读 · 0 评论 -
荷兰国旗问题---C++和JAVA
荷兰国旗问题给定一个数组arr,和一个数num,请把小于num的数放在数组的左边,等于num的数放在数组的中间,大于num的数放在数组的右边。原创 2019-05-22 22:34:21 · 1419 阅读 · 0 评论 -
冒泡排序——c++实现
C++实现冒泡算法#冒泡的算法介绍以升序排列为例来说,大的数字不断向后排,就像煮沸的水中的气泡一直往上升一样。冒泡算法它是通过不断比较相邻两数的大小来将最大的数字排列到最后的。例如 4 2 3 14和1相比,4大就和2交换位置变成2 4 3 1、j++4和3比较,4大就和3交换位置变成 2 3 4 1j++4和1比较,4大就和1交换位置变成2 3 1 4j++此时i=0...原创 2019-05-17 19:39:04 · 176 阅读 · 0 评论 -
选择排序----c++实现
选择排序选择排序和冒泡排序类似都是和相邻的比较,但不同的是它不交换数字而只交换下标。for (int i = 0; i < len; ++i) { int min = i;//定义最小值的下标, for (int j = i; j < len-i; ++j)//区别于冒泡的len-1-i,因为j不会越界//之所以冒泡和选择都要len-i是因为最大的是已经和所有的数比较过...原创 2019-05-18 19:49:42 · 177 阅读 · 0 评论 -
用数组实现栈的结构
用数组实现栈的结构栈是一种先进后出的结构,就像压子弹一样,先压入的子弹后打出这里我们谈一谈如何让用数组实现这一种结构#define _CRT_SECURE_NO_WARNINGS#include<iostream>#define max 10using namespace std; class ArrayStack{public: ArrayStack(...原创 2019-06-01 20:00:48 · 247 阅读 · 0 评论 -
插入排序---c++实现
插入排序插入排序和冒泡排序有点反着来的意思。冒泡排序是从数字不断向后比较,而插入则是从i开始向前不断比较。这里举个例子4 2 3 1for (int i = 1; i < len; ++i) { for (int j = i; j > 0; --j) { if (arr[j] < arr[j - 1]) { int temp = arr[j];...原创 2019-05-19 19:38:17 · 149 阅读 · 0 评论