自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(31)
  • 收藏
  • 关注

原创 KMP算法以及KMP算法的优化

KMP算法是基于串的模式匹配的一种比较时间复杂度较低的一种算法。那么什么是模式匹配以及KMP算法究竟好在哪里呢?串的模式匹配:子串的低位操作通常称为串的模式匹配,它求的是子串(模式串)在主串中的位置。我们这里对串的两种模式匹配进行一下对比第一种就是简单的模式匹配算法简单的模式匹配算法是很容易理解也是大部分同学常用的算法,也可以说是暴力匹配算法我们这里简单描述一下暴力匹配的算法思想分别用技术指针i和j只是主串S和模式串(子串)T中当前正待比较的字符位置算法思想为:从主串S的第一

2022-02-23 16:30:26 1389 2

原创 第二章 链表 求A和B链表元素交集并放在A中

#include <stdio.h>#include <stdlib.h>using namespace std;typedef struct LinkedList{ int data; struct LinkedList *next;}LinkedList,*List;int a[5]={1,2,3,4,5};int b[5]={3,4,5,6,7};int n=5;void build(List &L1,List &L2){...

2022-01-22 17:13:33 377

原创 第二章 链表 找出两个链表相同元素,放在新的链表中,原来的两个链表结构不能改变

#include <stdio.h>#include <stdlib.h>using namespace std;typedef struct LinkedList{ int data; LinkedList *next;}LinkedList,*List;int a[5]={1,2,3,4,5};int b[5]={4,5,6,7,8};int n=5;void build(List &L1,List &L2){ L1=...

2022-01-22 17:11:06 232

原创 第二章 链表 找出两个链表相同元素,放在新的链表中,原来的两个链表结构不能改变

#include <stdio.h>#include <stdlib.h>using namespace std;typedef struct LinkedList{ int data; LinkedList *next;}LinkedList,*List;int a[5]={1,2,3,4,5};int b[5]={4,5,6,7,8};int n=5;void build(List &L1,List &L2){ L1=...

2022-01-22 17:08:27 574

原创 第二章 链表 两个递增次序的单链表合并称为一个递减序列的单链表

#include <stdio.h>#include <stdlib.h>using namespace std;typedef struct LinkedList{ int data; struct LinkedList *next;}LinkedList,*List;int a[5]={1,2,3,4,5};int b[5]={6,7,8,9,10};int n=5;void build(List &L1,List &L2){...

2022-01-22 17:06:08 275

原创 第二章 链表 递增链表删除值相同的节点

#include <stdio.h>#include <stdlib.h>using namespace std;typedef struct LinkedList{ int data; struct LinkedList *next;}LinkedList,*List;int a[13]={1,2,3,3,3,3,4,4,5,6,7,8,9};int n=13;void build(List &L){ L=(List)malloc...

2022-01-22 17:05:26 102

原创 第二章 链表 对A链表按单序号节点和双序号节点分为A和B ,链表A相对顺序不变,链表B形成原来的逆序

#include <stdio.h>#include <stdlib.h>using namespace std;typedef struct LinkedList{ int data; struct LinkedList *next;}LinkedList,*List;int a[10]={1,2,3,4,5,6,7,8,9,10};int n=10;void build(List &L){ L=(List)malloc(size...

2022-01-22 17:03:32 158

原创 第二章 链表 把A链表的单节点和双节点分开 分别给A链表和新的B链表

#include <stdio.h>#include <stdlib.h>using namespace std;typedef struct LinkedList{ int data; struct LinkedList *next;}LinkedList,*List,*List2,*List3;int a[10]={1,2,3,4,5,6,7,8,9,10};int n=10;void build(List &L){ L=(Lis...

2022-01-22 17:02:06 92

原创 第二章 链表 递增次序输出最小节点 并释放空间

#include <stdio.h>#include <stdlib.h>using namespace std;typedef struct LinkedList{ int data; LinkedList *next;}LinkedList,*List;int a[6]={5,4,3,1,2,6};int n=6;void build(List &L){ L=(List)malloc(sizeof(LinkedList));...

2022-01-22 17:01:12 386

原创 第二章 链表 找出两个链表的公共节点

#include <stdio.h>#include <stdlib.h>using namespace std;typedef struct LinkedList{ int data; struct LinkedList *next;}LinkedList,*List,*List2; //直接定义两个头指针int a[5]={1,2,3,4,5};int b[5]={4,5,6,7,8};int n=5;void build(List &am...

2022-01-22 16:56:03 67

原创 第二章 链表 删除给定范围内的节点

#include <stdio.h>#include <stdlib.h>using namespace std;typedef struct LinkedList{ int data; struct LinkedList *next;}LinkedList,*List;int a[5]={5,6,9,2,7};int n=5;void build(List &L){ L=(List)malloc(sizeof(LinkedLi...

2022-01-22 16:54:39 276

原创 第二章 链表 节点排序

#include <stdio.h>#include <stdlib.h>using namespace std;typedef struct LinkedList{ int data; struct LinkedList *next;}LinkedList,*List;int a[6]={3,2,5,4,1,6};int n=6;void build(List &L){ L=(List)malloc(sizeof(LinkedLi...

2022-01-20 19:00:37 374

原创 第二章 链表 链表逆置空间复杂度为O(1)

#include <stdio.h>#include <stdlib.h>using namespace std;typedef struct LinkedList{ int data; struct LinkedList *next;}LinkedList,*List;int a[5]={1,2,3,4,5};int n=5;void build(List &L){ L=(List)malloc(sizeof(LinkedLi...

2022-01-20 18:58:18 304

原创 第二章 链表 删除值最小节点

#include <stdio.h>#include <stdlib.h>using namespace std;#define Min 0x7fffffff;typedef struct LinkedList{ int data; struct LinkedList *next;}LinkedList,*List;int a[5]={5,4,3,1,2};int n=5;void build(List &L){ L=(Lis...

2022-01-20 18:56:59 332

原创 第二章 链表 逆序输出带头结点的节点值

#include <stdio.h>#include <stdlib.h>using namespace std;typedef struct LinkedList{ int data; struct LinkedList *next;}LinkedList,*Link;int a[4]={1,2,3,4};int n=4;void build(Link &L){//建立链表 L= (Link)malloc (sizeof(Li...

2022-01-20 18:56:21 262

原创 第二章 链表 删除带头结点的单链表值为x的节点并释放其空间

#include <stdio.h>#include <stdlib.h>using namespace std;int n=5;int a[5]={1,2,3,5,5};typedef struct LinkedList{ int data; struct LinkedList *next;}LinkedList,*List;//LinkedList使我们给这个结构体赋的变量名//List是定义了一个指针作为头结点void build(Li...

2022-01-20 18:55:27 1017

原创 第二章 链表 递归算法删除不带头结点的单链表值为x的节点

#include <stdio.h>#include <stdlib.h>using namespace std;typedef struct LinkedList{ int data; struct LinkedList *next;//指针}LinkedList;int a[4]={1,2,3,4};int n=4;void buildList(LinkedList *l){ LinkedList *s; LinkedList...

2022-01-20 18:54:43 277

原创 第二章 线性表 求三个数组的最小距离

#include <stdio.h>using namespace std;#define Min 0x7fffffff/*求三个升序数组的最小距离1.算法思想其实就是求出这三个数组的最相近的数再求这三个数的距离就是这三个数a-b绝对值加b-c绝对值加a-c绝对值还是需要遍历一个死循环遍历到某一个数组完毕即可需要一个变量min我们首先初始化min为一个足够大的数这里我们define了一个0x7fffffff这个0x7fffffff就是三十二位计算机中带符号最大的整数

2022-01-20 18:53:37 138

原创 第二章 线性表 求数组中没有出现的最小正整数

#include <stdio.h>using namespace std;/*给定一个数组求这个数组中没有出现的最小正整数1.算法思想首先要求没有出现的最小正整数最差情况就是在这个数组中1~n都出现了那么没有出现的最小正整数就是n+1所以没有出现的最小正整数肯定在1~n+1之中要求时间高效那么我们利用空间换时间的思想再创建一个数组b初始化b都为0对a进行遍历如果遍历的元素大于0小于n+1那么就把这个元素的值当做下标放在b中然后遍历b求出没有除了下标为0的第一次出现0的.

2022-01-20 18:52:29 600

原创 第二章 线性表 求主元素

#include <stdio.h>using namespace std;/*给一个数组求主元素根据题意可知题目中表达的主元素就是值当同一个值的个数大于整体个数的一半时那么这个数就是主元素1.算法思想可以设计一个变量count先把第一个数当主元素往后遍历如果相同就count++如果不同count--如果count小于了0就把当前比较的数当做主元素继续遍历 最后还有一个统计这个数是否大于整体数量的1/2的比较如果是就返回主元素如果不是就返回-12.代码实现3.时间.

2022-01-20 18:51:37 243

原创 第二章 线性表 求两个线性表的中位数

#include <stdio.h>using namespace std;#define Max 50/*对两个线性表求中位数也就是合并乘有序的线性表求中位数题目的中位数和平时用的中位数不同这里要求求出合并后的长度并取length/2向上取整的位置作为中位数也就是下标为Length/2-1的下标为中位数1.算法思想设计一个合并函数将两个等长升序的线性表合并成为一个有序的线性表在用主函数求出中位数2.算法实现3.时间空间复杂度分析时间复杂度是O(m+n)取m或...

2022-01-20 18:50:31 170

原创 第二章 使线性表原来的 {ab}变为{ba}

#include <stdio.h>using namespace std;#define Max 50/*先整体逆置再a和b逆置 是ab转换为ba1.基本思想如上文把ab转为ba可以使用两次逆置需要逆置函数2.代码实现3.时间空间复杂度三个递归复杂度分别为O(n/2),O((n-m)/2),O(m/2)取最大并省去常数所以时间复杂度为O(n)空间复杂度为O(1)因为一直对一个线性表操作*/struct SqlList{ int data[M...

2022-01-18 16:09:56 801

原创 第二章 线性表 有序递增线性表最少时间找到值为x元素,如果找到和后一位互换,如果找不到指定元素那么添加到线性表中,使线性表仍然递增

#include <stdio.h>using namespace std;#define Max 50struct SqlList{ int data[Max]={2,4,6,8,9,10,12,13}; int length=8;};bool halfSelect(SqlList &s,int left,int right,int x){ if(left>=right){ return false; } i...

2022-01-18 16:08:03 162 1

原创 第二章 线性表 a和b为{a,b}在线性表中使a和b互换形成{b,a}

#include <stdio.h>using namespace std;#define Max 50/*这道题是针对a和b在线性表s中要求把a和b的位置交换利用三次逆转分别为整体逆转一次a和b逆转各一次,这里的 a和b逆转与整体逆转是可以位置调换的 先a和b逆转也行但是整体逆转不能加到a和b逆转中间这道题在逻辑和实现方面都是有些许难度的其中x和y为a和b线性表的左起始下标和右结束下标*/struct SqlList{ int data[Max]={1,2...

2022-01-18 16:06:29 174

原创 第二章 线性表 合并两个有序表生成新的有序表

#include <stdio.h>using namespace std;#define Max 50struct SqlList{ int data[Max]; int length;};bool merge(SqlList &s,SqlList &a,SqlList &b){ if(a.length+b.length>s.length){ return false; } int i=...

2022-01-18 16:04:31 1120

原创 第二章 线性表 有序表删除重复元素

#include <stdio.h>using namespace std;#define Max 50struct SqlList{ int a[Max]={1,2,3,3,3,5,5,7,7,8,9,10,11,11,22,22,23}; int length=17;};void delCommen(SqlList &s){ int k=0; if(s.length==0){ printf("线性表为空\n");...

2022-01-18 16:03:14 201

原创 第二章 线性表 删除包括s和t并且s<t的所有元素

#include <stdio.h>using namespace std;#define Max 50/*上一题是有序表定义的线性表是无序表删除在某个区域的数删除的区域包含我们定义的数,也要删*/struct SqlList { int a [Max] = {5,6,8,9,9,8,4,6,9,2,3,8,1,3,6}; int length = 15;};void del(SqlList &s,int x,int y) { int...

2022-01-18 16:02:19 90

原创 第二章 线性表 删除不包括s和t并且s<t的所有元素

#include <stdio.h>using namespace std;#define Max 50/*定义的线性表是有序表删除在某个区域的数*/struct SqlList{ int a[Max]={1,2,3,4,4,4,5,5,6,6,7,7,7,7,8,8,8,9,9,10,10,11,12,13}; int length = 24;};void del(SqlList &s,int x,int y){ int k=0;...

2022-01-18 16:01:26 49

原创 第二章 线性表 删除值为x的元素 时间复杂度为O(n)空间复杂度为O(1)

#include <stdio.h>using namespace std;#define Max 50/*这个题表明要删除数组中值为某个数的所有元素同时这也伴随着整个数组的数被删除后这个数的元素会往前移动并且数组的整体的长度会变小*/struct SqlList{ int a[Max]={5,2,0,1,3,1,4}; int length=7;};void del(SqlList &s,int x){ int k=0;//用来记录数...

2022-01-18 15:59:59 463

原创 第二章 线性表 逆置元素 空间复杂度为O(1)

#include <stdio.h>using namespace std;#define Max 50/*题目上表明空间复杂度是1所以我们只能对一个结构体进行操作进行逆置的规律就是把第i个元素和第n-i-1个元素互换即可这个规律才是这个空间复杂度为1的重点时间复杂度为n/2*/struct SqlList{ int a[Max]={1,2,3,4,5,6,7}; int length=7;};void reverse(SqlList &s...

2022-01-18 15:58:00 390

原创 数据结构 线性表 删除最小返回最小值,空出的由最后元素填补

第二章 线性表 删除最小返回最小值,空出的由最后元素填补#include <stdio.h>using namespace std;#define Max 50struct SqlList{ int a[Max]={5,9,2,37,1,8,12,23}; int length=8;};bool Listdelete(SqlList &s,int &ele){//需要加引用符 if(s.length==0){ ret...

2022-01-18 12:33:10 225

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除