- 博客(25)
- 收藏
- 关注
原创 关于c/c++指针改变变量地址小坑(指针的指针)
#include "stdio.h" #include "stdlib.h" #include <iostream>using namespace std;int change(int *n,int *m){ m = n;} int change2(int **n,int **m){ *m = *n;} int main(void){ int a = 1,b = 2; int *c = &a,*d = &b; cout <&l.
2021-08-17 17:19:29
574
原创 c++关于指针或者数组作为函数参数时的坑
直接放代码吧,主要还是要理解直接创建的数组空间和先创建指针后面再创建空间的区别#include "stdio.h" #include "stdlib.h" #include <iostream>using namespace std;int getNum(int **arr);int getNum2(int arr[][20]);int getNum3(int *arr);int getNum4(int arr[]);int getNum5(int *arr[20])
2021-08-11 22:34:23
150
原创 c语言:计算二叉树的深度递归、非递归算法
//递归int search_btDepthRecursion(LINKBINTREE *bTree){// 返回最大深度,递归算法 if(!bTree) return 0; return (search_btDepthRecursion(bTree->lchild)>search_btDepthRecursion(bTree->rchild)?search_btDepthRecursion(bTree->lchild):search_btDepthRecursion
2021-01-08 17:25:01
1176
原创 c语言:线索二叉树的创建、遍历
#include <stdio.h>#include <stdlib.h>#define DATATYPE char#define MAXSIZE 100typedef struct node{ DATATYPE data; int ltag,rtag; struct node *lchild,*rchild;}THREADBT;THREADBT *init_threadBt(){// 创立二叉树 DATATYPE data[] = "abcdef#";
2021-01-08 00:26:45
348
原创 c语言:完全二叉树的非递归先、中、后序、层次遍历
#include <stdio.h>#include <stdlib.h>#define DATATYPE char#define MAXSIZE 100typedef struct node{ DATATYPE data; struct node *lchild,*rchild;}LINKBINTREE;LINKBINTREE *create(){ int num,father,j = 0; LINKBINTREE *pArr[MAXSIZE],*p; c
2021-01-06 17:12:33
201
原创 c语言:完全二叉树的建立与递归遍历
#include <stdio.h>#include <stdlib.h>#define DATATYPE char#define MAXSIZE 100typedef struct node{ DATATYPE data; struct node *lchild,*rchild;}LINKBINTREE;LINKBINTREE *create(){ int num,father,j = 0; LINKBINTREE *pArr[MAXSIZE],*p; c
2021-01-06 17:09:07
555
原创 关于数组作为函数参数时的size
在c语言里,如果函数参数是数组类型,那么c语言会自动将该形参变指向传入的那个数组的指针,因此在函数内部调用sizeof的到的不是传入的数组大小,而是作为datatype指针的大小:
2020-12-26 18:50:31
490
1
原创 char*和char[]的区别
char*指的是一个指向储存区的指针,其指针指向的值不能改变运行:char[]则会自动储存类型的变量,会自动拷贝一份值到栈中,因此修改char[]的变量是可以的:
2020-12-25 18:51:42
285
原创 关于c语言在循环赋值字符时出现乱码情况
c语言有个很奇怪的情况,有时候我们使用循环给一个新的字符数组赋值时打印出来的字符串是乱码,明明赋值都没有错:但是运行起来是这样的:当循环次数大于等于3时:最后经过测试发现:当循环小于等于3的次数时,循环赋值字符数组并不会给字符数组的末尾加上’\0’,才会导致这样的情况,解决这种问题也很简单,就是当字符数组需要赋值的字符个数小于3时在字符数组的末尾加上’\0’即可,如:...
2020-12-24 22:40:54
1492
原创 c语言:队列的链式存储结构
# include <stdio.h># include <stdlib.h># define DATATYPE int typedef struct node{ DATATYPE data; struct node *next;}linkqueue;typedef struct{ linkqueue *front,*rear; int len; }LINKQUEUE;void init_linkqueue(LINKQUEUE *Lq){ linkqu
2020-12-22 09:46:35
194
原创 c语言:队列的顺序存储实现
# include <stdio.h># include <stdlib.h># define MAXSIZE 11# define DATATYPE int typedef struct{ DATATYPE data[MAXSIZE]; int rear,front;}QUEUE;void init_queue(QUEUE *q){ q->front = q->rear = 0;}int isEmpty(QUEUE *q){ int n;
2020-12-21 17:53:24
178
原创 c语言:利用栈特性实现判断字符串是否中心对称
# include <stdio.h># include <stdlib.h># define MAXSIZE 10# define DATATYPE inttypedef struct node{ DATATYPE data[MAXSIZE]; int top;}SEQSTACK;void init_stack(SEQSTACK *S){ S->top = -1;}void stack_push(SEQSTACK *S,DATATYPE n){
2020-12-20 23:17:48
3100
1
原创 c语言:栈的链式存储结构
# include <stdio.h># include <stdlib.h>typedef struct node{ int data; struct node *next;}stackNode;typedef struct{ stackNode *stackTop;}LINKSTACK;//采用两个结构体可以避免使用**的场景,并且后期方便管理void init_linkStack(LINKSTACK *linkstack){ linkstack-&g
2020-12-20 18:32:29
141
原创 栈的顺序存储
# include <stdio.h># include <stdlib.h># define MAXSIZE 10typedef struct node{ int data[MAXSIZE]; int top;}SEQSTACK;void init_stack(SEQSTACK *S){ S->top = -1;}void stack_push(SEQSTACK *S,int n){ if(S->top==MAXSIZE-1){ pri
2020-12-20 15:29:28
204
1
原创 c语言循环链表实现约瑟夫环
#include <stdio.h>#include <stdlib.h> typedef struct node{ int data; struct node *next;}LINKLIST;LINKLIST *initList(int n){// 创建一个循环链表 ,赋予的值分别为1,2,3,4.... LINKLIST *head = (LINKLIST*)malloc(sizeof(LINKLIST)); LINKLIST *p = head; he
2020-12-19 18:14:46
418
1
原创 c语言链表实现稀疏多项式之间的加减(顺序结构链表)
#include <stdio.h>#include <stdlib.h> // 顺序多项式的合并typedef struct node{ int coef;//系数 int pow;//指数 struct node *next;}POLYNOMIAL;POLYNOMIAL *polyRcreate(){// 尾插入法创建链表 int coef,pow,num = 1; POLYNOMIAL *head,*last,*p; head = (POLYN
2020-12-04 23:39:15
1514
2
原创 c语言单链表的实现,包括链表的创建、插入、查询、删除、打印、长度计算
#include <stdio.h>#include <stdlib.h> typedef struct node{ char data; struct node *next;}LINKLIST;// 链表初始化操作,返回一个空链表 LINKLIST *INITLIST(){ LINKLIST *head; head = (LINKLIST*)malloc(sizeof(LINKLIST)); head->next = NULL; return h
2020-11-25 00:46:47
658
原创 关于c语言指针中传参不改变数据问题
在c语言里面我们有时候会出现如下情况:明明传入的形参是指针,但是在函数改变指针的指向后但是数据却不会发生改变,这个很有可能是我们忽略了在函数中我们是否使用了局部参数的地址(该地址在函数结束后再次调用其他函数时会被回收),如下:#include <stdio.h>#include <stdlib.h> typedef struct test{ int a; int b;}TEST;void change(TEST *t){// test1是局部变量,会被回收
2020-11-24 19:01:58
2356
原创 c语言malloc和free函数
int mallocSize(){ void *p; int cnt = 0; while((p = malloc(100*1024*1024)))//malloc分配内存空间,返回void指针,若分配失败则返回NULL { cnt++; } printf("成功分配了%d00MB的空间",cnt); free(p); //free函数:释放malloc过来的内存(赋值的不行,例如*p = &i的内存不能释放;先malloc后来p++后也不能释放了,因为改变了p的指向;无值的指
2020-11-13 18:36:44
212
原创 c语言指针与const的关系
c语言指针与const的关系下面展示一些 内联代码片。#include <stdio.h>int main(){ int i1 =1; int i2 = 10; int j = 111; //1、不能修改*p1的值(p1指向的值),但是可以修改p1的指向以及i1自身的值 const int *p1 = &i1;//这种写法等同于int const *p1 = &i1; // *p1 = 10;//error *p1++;//ok(修改地址指向,注意运算
2020-11-11 16:10:51
124
原创 linux配置pptp
安装ppp(yum可以直接安装) 和pptpd(wget安装,可以去rpmfind.net找到下载地址)2、配置 /etc/pptpd.conf,配置自身网卡和连接了vpn主机的网卡,不做要求的话取消注释即可3、配置 /etc/ppp/chap-secrets,创建连接时账号密码4、防火墙放行(firewall-cmd --zone=trusted --add-interface=ppp+ --per)以及放行端口(firewall-cmd --zone=external --add-port.
2020-06-25 10:48:09
1035
原创 前台调用云数据库
前台云数据库操作一些技巧(1)先给定环境生成database对象 const database = wx.cloud.database({ env: '********', traceUser: true })(2)通过数据表的名称得到该数据表的对象//一次性获取数据表里面的20条数据,这是系统默认的//写法1: database.collection('add').get({ success: res => {
2020-06-17 10:44:07
322
原创 微信小程序常用模块(form+switch+slider+checkbox+radio+textarea+picker等)
1、页面区域// wxml区域<view class="container"> <form bindsubmit="output"> <view class="title"> Form表单 </view> <view id="sitchArea"> <view class="mySwitch"> <text>siwthch组件1</text>
2020-06-17 09:57:06
416
原创 Unity中UGUI中的图片拖拽问题
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.EventSystems;public class DrawPicture : MonoBehaviour,IDragHandler,IPointerDownHandler{ RectTrans...
2019-11-09 23:50:12
524
原创 C#将一个正整数分解质因数
C#将一个正整数分解质因数public static void Fun12() { int count = Convert.ToInt32(Console.ReadLine()); int startCount = count; for (int i = 2; i < count; i++) ...
2019-11-09 23:33:14
1158
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人