
C/C++语言
C/C++的代码合集
淡若栀子花
华为HCIE云计算专家
阿里云ACE认证-阿里云云计算架构师认证
HCIP-Big-Data 华为认证ICT高级大数据工程师
展开
-
习题5-4 交换学生 UVa10763
本题直接用数组进行模拟即可#include<iostream>#include<stdio.h>#include<stdlib.h>#include<algorithm>using namespace std;int num[500001],num1[500001];int main(){ int n; while((cin>>n) && n){ int flag = 1; ...原创 2020-10-12 22:28:26 · 703 阅读 · 0 评论 -
习题5-2 Ducci序列(Ducci Sequence, ACM/ICPC Seoul 2009, UVa1594)C语言编写
习题5-2 Ducci序列(Ducci Sequence, ACM/ICPC Seoul 2009, UVa1594)A Ducci sequence is a sequence of n-tuples of integers. Given an n-tuple of integers (a1, a2, · · · , an),the next n-tuple in the sequence is formed by taking the absolute differences of neigh.原创 2020-10-12 21:47:37 · 715 阅读 · 0 评论 -
哈夫曼树的C语言详解
哈夫曼树的C语言详解1)一些名词的解释: 路径:在一棵树中,一个结点到另一个结点之间的通路,称为路径。图 1 中,从根结点到结点 a 之间的通路就是一条路径。 路径长度:在一条路径中,每经过一个结点,路径长度都要加 1 。例如在一棵树中,规定根结点所在层数为1层,那么从根结点到第 i 层结点的路径长度为 i - 1 。图 1 中从根结点到结点 c 的路径长度为 3。 结点的权:给每一个结点赋予一个新的数值,被称为这个结点的权。 结点的带权路径长度:指的是从根结点到该结原创 2021-03-28 23:41:51 · 33612 阅读 · 5 评论 -
BFS(基于C语言的简单实现)
BFS(基于C语言的简单实现) 把根结点放到队列的末尾 每次从队列的头部取出一个元素,查看这个元素所有的下一级元素,把它们放到队列的末尾。并把这个元素标记为它下一级元素的前驱 找到所要找的元素时结束程序 如果遍历整个树都还没有找到,则结束程序 #include<stdio.h>#include<stdlib.h>#define MAX_VALUE 4int visit[MAX_VALUE];typedef struct ArcNode原创 2021-03-28 23:36:57 · 21378 阅读 · 0 评论 -
DFS(基于C语言的简单实现)
DFS(基于C语言的简单实现)一般步骤(1) 把初始状态放入数组中,设为当前状态;(2) 扩展当前的状态,产生一个新的状态放入数组中,同时把新产生的状态设为当前状态;(3) 判断当前状态是否和前面的重复,如果重复则回到上一个状态,产生它的另一状态;(4) 判断当前状态是否为目标状态,如果是目标,则找到一个解答,结束算法。(5) 如果数组为空,说明无解。#include<stdio.h>#include<stdlib.h>#define MAX_VALUE .原创 2021-03-28 23:35:16 · 23835 阅读 · 0 评论 -
快慢指针与头插法与尾插法(基于C语言)
快慢指针的妙用1.找中间值一般的思路是:先遍历一次链表,记录住一共有多少个节点,然后,再次遍历找寻中点。利用快慢指针,我们来看看这个问题会变成什么样。思路如下:我们把一个链表看成一个跑道,假设a的速度是b的两倍,那么当a跑完全程后,b刚好跑一半,以此来达到找到中间节点的目的。2.判断链表中的环还是把链表比作一条跑道,链表中有环,那么这条跑道就是一条圆环跑道,在一条圆环跑道中,两个人有速度差,那么迟早两个人会相遇,只要相遇那么就说明有环。3.删除倒数第n个节点删除倒数第n个节点,.原创 2021-03-21 00:02:58 · 29516 阅读 · 0 评论 -
线性表的顺序存储(C语言编写(非常基础))
#include<iostream>#include<stdio.h>#include<stdlib.h>//包含了exit函数#include<string.h>using namespace std;struct Arr{ int *pBase;//存储的是数组第一个元素的地址 int len;//数组所能容纳的最大元素的个数 int cnt;//当前数组有效元素的个数};void init_arr(struct Arr *pArr.原创 2021-03-20 23:52:45 · 9537 阅读 · 0 评论 -
链表(C语言编写)
基于C语言编写的链表,可以直接复制,可以运行#include<stdio.h>#include<stdlib.h>typedef struct Student{ int num; char name[10]; struct Student *pnext;}STU;STU*GreatList(){ STU*p = (STU*)malloc(sizeof(STU)); p->pnext = NULL; return p;}void AddNode原创 2021-03-16 23:26:40 · 36685 阅读 · 0 评论 -
通讯录管理系统(C语言编写)
#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<iostream>#include<string>#include<windows.h>using namespace std;typedef struct student{ int num; char name[20]; char tel[15]; struct stude.原创 2021-03-16 23:24:33 · 17909 阅读 · 0 评论 -
希尔排序(C语言)
#include<stdio.h>#include<stdlib.h>//堆排序用于查找最大值 或者 最小值void show(int *p, int n){ for (int i = 0; i < n;i++) { printf("%4d", p[i]); } printf("\n");}void shellsort(int *p, int length){ int d = length / 2;//增量 while (d >= 1)//.原创 2021-03-15 23:38:50 · 15197 阅读 · 0 评论 -
堆排序(C语言)
#include<stdio.h>#include<stdlib.h>//堆排序用于查找最大值 或者 最小值void show(int *p, int n){ for (int i = 0; i < n;i++) { printf("%4d", p[i]); } printf("\n");}void findmax(int *arr, int size){ for (int j = size - 1; j>0; j--)//从尾部循环到头部.原创 2021-03-15 23:38:00 · 6264 阅读 · 0 评论 -
快速排序(基于C语言)
#include<stdio.h>#include<stdlib.h>int a[100];void quicksort(int left,int right){ int i,j,temp; if(left>right) return; temp = a[left];//temp存储基准数 i = left,j = right; while(i!=j){ //顺序很重要 从右往左找 while(a[j]>=temp &&.原创 2021-03-15 23:36:36 · 24467 阅读 · 0 评论 -
桶排序(基于C语言)
#include<stdio.h>#include<stdlib.h>int a[100];int main(){ int n,t; scanf("%d",&n); for(int i = 0;i<n;i++){ scanf("%d",&t); a[t]++; } for(int i =0;i<10;i++) printf("%d ",a[i]); printf("\n"); //这里的i < 10 是代表1.原创 2021-03-15 23:35:58 · 19564 阅读 · 0 评论 -
迷宫走法(基于BFS)
#include<stdio.h>#include<string.h>#include<stdlib.h>/*测试数据5 40 0 1 00 0 0 00 0 1 00 1 0 00 0 0 11 1 4 37*/struct node{ int x; int y; int f; int s;};int main(){ int n,m,tx,ty,px,py,startx,starty; int a[51][51]={0}.原创 2021-03-15 23:32:54 · 9430 阅读 · 0 评论 -
迷宫走法(基于DFS)
#include<stdio.h>#include<string.h>#include<stdlib.h>/*测试数据5 40 0 1 00 0 0 00 0 1 00 1 0 00 0 0 11 1 4 37*/int n,m,min=9999999;int px,py;int a[51][51],book[51][51];void dfs(int x,int y,int step){ int next[4][2]={{0,1}.原创 2021-03-15 23:30:48 · 9295 阅读 · 0 评论 -
n的阶乘(基于DFS)
#include<stdio.h>#include<string.h>#include<stdlib.h>int book[10];//判断是否走过该步 int a[10];//存储走过的步 int n;void dfs(int step){ if(step==n+1) { for(int i = 1;i<=n;i++) printf("%d",a[i]); printf("\n"); return; } for(int...原创 2021-03-15 23:29:17 · 9226 阅读 · 0 评论