自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 KMP算法代码详解

kmp算法代码详解

2022-06-12 17:07:35 785 1

原创 假设 顺序表 L中的元素按从小到大的次序排列,设计算法以删除表中重复的元素, 并要求时间尽可能少。(最多三个重复数)

#include <iostream>#include <cmath>#include<iomanip>using namespace std;//用线性表合并两个有序表enum myerrorcode { rangeerror, success, overflow, underflow };template<class T>class list{public: T data[1000]; int count; list() { .

2022-04-09 11:25:15 1328

原创 设计算法将递增有序线性表A/B的元素值合并为另一个递增有序的表C

#include <iostream>#include <cmath>#include<iomanip>using namespace std;//用线性表合并两个有序表enum myerrorcode{ rangeerror,success,overflow,underflow};template<class T>struct node{ T data; node* next;};template<class T>cl.

2022-04-04 13:26:58 526

原创 假设链表A、B分别表示两个集合,设计算法以求解C= A∪B, C= A∩B, A=A-B

#include <iostream>using namespace std;enum myerror_code { success, extent_error };template<class T>struct node{ T data; node* last, * next;};template<class T>class list{public: list() { head = new node<T>; head-.

2022-04-03 16:41:20 1587

原创 线性表中元素地址逆置

#include <iostream>#include <cmath>#include<iomanip>using namespace std;enum error_code1 { success, arrangeerror };template<class T>struct node{ T data; node* next; node* prior;};template<class T>class list{p.

2022-03-28 18:11:42 57

原创 用顺序队列、链队列实现杨辉三角的输出

顺序队列:#include<iostream>#include<cstdlib>#include<ctime>#include<string>using namespace std;enum myerror_code { success, underflow, overflow };//进5-2+3-1//+5-2+3-7template<class T>struct node{ T data; node* next

2022-03-26 15:58:09 1127

原创 c++练习题——杨辉三角

设计函数计算n(1<=n<=25)行的杨辉三角,存放在二维数组中,再输出。#include<iostream>#include<iomanip>using namespace std;int main(){ int n; cin >> n; n = n; int m = 2 * n - 1; int** arr = new int * [m]; for (int i = 0; i < m;

2021-12-26 10:39:06 245

原创 c++练习题——是素数吗

向程序输入一个正整数,请你判断该正整数是否是素数#include<iostream>using namespace std;int zhishu(int a){ int arr[100]; arr[0] = a; arr[2] = 0; arr[1] = 1; int j = 2; for (int i = 2; i <a ; i++) { if (a % i == 0&&a!=2) { arr[j] = i; j++;

2021-12-26 10:26:31 768

原创 c++练习题——求符合条件的数

求满足下列条件的最小自然数 x:(1)个位数是 8;(2)将个位数移至最高位,所得的新数是原数的 4 倍。#include<iostream>#include<cmath>using namespace std;/*求满足下列条件的最小自然数 x:(1)个位数是 8;(2)将个位数移至最高位,所得的新数是原数的 4 倍。*/int panduan(int x){ int count = 0; int a = x % 10; if (a == 8) { i

2021-12-26 10:14:18 900

原创 c++练习题——返回数值

返回整数从右边起某一指定位的数值(如int digitR(12345,2),返回4)#include<iostream>#include<cmath>using namespace std;int shuzhi(int a,int b){ // 返回整数从右边起某一指定位的数值(如int digitR(12345, 2), 返回4) int d = pow(10, b); int c = (a%d) / pow(10, b - 1); return c;}

2021-12-26 10:05:17 486

原创 两种冒泡排序的不同写法

冒泡排序的基本思想:相邻两数进行比较,大的向后移,经过第一轮两两比较和移动,最大的元素移动到了最后,第二轮次大的位于倒数第二个,依次进行。两种冒泡排序的不同:从左往右比还是从右往左比两种冒泡排序本质相同第一种(从左往右):for(int loop=0;loop<len-1;loop++){ for(int i=0;i<len-1-loop;i++) if(array[i]> array[i+1]){ int t = array[i]; arr

2021-12-19 15:51:54 189

原创 统计输入数字的位数(int型)

#include<iostream>using namespace std;int main(){ int num; int cnt=1; cin>>num; while(num/10!=0) { num=num/10; cnt++; } cout<<cnt<<endl; }

2021-12-09 19:25:39 169

原创 取double,float的小数点后几位

使用setprecision函数取#include <stdio.h>#include <iostream>#include <iomanip>//包涵set函数的头文件using namespace std;int main(){ const double pi=3.14; double a,b,c,d; cin>>a; cin>>b; cout<<setiosflags(io

2021-12-09 19:16:18 165

原创 归并排序代码详解(注释)

注:源代码和图片来自 合肥工业大学 计算机学院 方帅老师的课件侵权必删#include<iostream>using namespace std;//按照标号看void merg(int a[], int lmin, int rmin, int rmax)/*10、以最后四个数为例,lmin为数组首地址,记为左标记,rmin为右边第一个地址,即2的地址,记为右标记,rmax为数组末尾的地址。*/{ int temp;//11、定义一个可以临时变量储存值 while.

2021-11-30 13:59:09 542

空空如也

空空如也

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

TA关注的人

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