- 博客(67)
- 资源 (1)
- 问答 (2)
- 收藏
- 关注
原创 结构体所占字节的计算
#include<stdio.h>#pragma pack(show) // 8 默认对齐模数 生成解决方案的时候,会输出“杂项”说明,说明默认对齐模数比//对于自定义数据类型,内存对齐规则如下://1. 从第一个属性开始,偏移量为0//2. 从第二个属性开始,地址要放在该类型的整数倍与对齐模数比中的最小值的整数倍上 //3. 所有的属性都计算结束后,整体再做二次对齐,整体...
2019-08-03 12:31:40
638
原创 c/c++ 结构体嵌套结构体的偏移量计算
#include<stdio.h>#include<stddef.h>struct Person{ char a; int b;};struct Person2{ char c; int d; struct Person e;};void test01() { struct Person2 p2 = {'c',10,'a',20}; i...
2019-08-03 11:17:03
729
原创 c/c++ 二维数组作函数的参数
#include<stdio.h>#include<string.h>#include<stdlib.h>//二维数组作函数的参数,退化成一个指向一维数组的指针变量void printArray(int(*p)[3],int row,int col) { for (int i = 0; i < 3;i++) { for (int j =...
2019-07-28 17:43:40
286
原创 c/c++ 如何定义数组的指针
#include<stdio.h>#include<stdlib.h>#include<string.h>//如何定义数组的指针(三种方式)//先定义出数组的类型,再通过类型创建数组的指针void test01() { int arr[] = {1,2,3,4,5}; typedef int(ARRAY_TYPE)[5]; // ARRAY_...
2019-07-28 17:16:26
3169
原创 c/c++ 通过异或运算实现两个数的交换
void test07() { int num1 = 2; int num2 = 3; printf("交换前:"); printf("num1= %d,num2 = %d\n", num1, num2); num1 = num1 ^ num2; num2 = num1 ^ num2; num1 = num1 ^ num2; printf("交换后:"); printf("nu...
2019-07-28 15:43:01
1168
原创 c/c++ sizeof与strlen的区别
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<stddef.h>void test01() { //sizeof统计 \0,strlen不统计\0,遇到\0就结束 char str[] = "hello\012world"; // \012是八进制,下转十进制...
2019-07-21 18:45:52
244
原创 c/c++通过地址偏移访问或修改变量
#include<stdio.h>#include<string.h>#include<stdlib.h>typedef struct Person { char c1; int t1; char c2; int t2;} myPerson;void test() { myPerson mp = {1,100,2,200}; /* ...
2019-07-14 15:20:58
1637
原创 c/c++ base64加密实现
#include<iostream>#include<string>#include<bitset>#include<vector>#include<stdlib.h>#include<time.h>#include<sstream>typedef std::bitset<8> byte...
2019-07-11 17:03:54
639
原创 C/C++版AES加密实现
一、参考文档1.https://www.jianshu.com/p/3840b344b27c?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation2.https://songlee24.github.io/2014/12/13/aes-encrypt/...
2019-07-11 09:13:36
1292
原创 c语言_二叉排序树增删
一、tree.h#pragma once#include<stdio.h>#include<stdlib.h>typedef struct binary_sort_tree { int* data; void* left; void* right; char ptr;}bst;#define BST_SIZE sizeof(bst)bst* tre...
2019-06-24 16:42:05
285
原创 c语言_贪吃蛇
c语言_贪吃蛇一、Snake.h#pragma once#define WIDTH 60#define HIGH 20int score = 0;//偏移量int dx = 0;int dy = 0;int lx = 0;int ly = 0;struct Body{ //横坐标 int x; //纵坐标 int y;};struct Snak...
2019-06-09 19:38:16
477
原创 c语言复制大文件
代码:#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/types.h>#include <sys/stat.h>#define SIZE 1024*1024*8int main(int argc, const char * arg...
2019-06-02 14:16:39
518
原创 c语言大文件排序
一、生成大文件int main(void) { FILE* fp = fopen("D:/数据.txt","w"); if (!fp) { printf("打开文件失败/n"); return -1; } srand((size_t)time(NULL)); for (int i = 0; i < SIZE;i++) { fprintf(fp,"%d\n"...
2019-05-31 10:26:13
665
原创 c语言文件操作
一、fgetcint main(void) { FILE* fp = fopen("D:/hello.txt","r"); if (!fp) { printf("文件无法打开!"); return -1; } char ch; while ((ch=fgetc(fp))!= EOF) { printf("%c",ch); } puts(""); fclose...
2019-05-29 14:46:12
223
原创 c语言结构体指针使用
一、代码#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<string.h>#include<stdlib.h>struct student1{ char* name; int age; char* sex; int* score; char* addr;};typede...
2019-05-28 14:20:55
216
原创 c语言二级指针开辟空间
一、图示二、代码int** p = (int**)malloc(sizeof(int*)* 3);//p中存的地址是开辟的空间的首地址 for (int i = 0; i < 3;i++) { *(p + i) = (int*)malloc(sizeof(int) * 3);//p+i中存的地址是开辟的空间的首地址 } for (int i = 0; i < 3...
2019-05-28 09:13:53
2449
1
转载 java_利用虚引用关闭相关的资源
转载自: https://blog.youkuaiyun.com/tugangkai/article/details/79593495gc回收对象时关闭相关的流一、代码1、FileOperationpublic class FileOperation { private FileOutputStream outputStream; private FileInputStream inp...
2019-05-24 14:25:41
391
原创 c语言统计字符个数
1.统计各字符串出现的次数int main(int argc, const char * argv[]) { char chs[] = "fjadsjfjdsajfkjdskj"; int arr[26] = {0};//26个字母 for (int i = 0; i < sizeof(chs); i++) { if(*(chs+i)){ ...
2019-05-21 23:00:01
24967
2
原创 c语言随机数的产生
#include <stdio.h>#include <stdlib.h>#include <time.h>int main(int argc, const char * argv[]) { //添加随机数种子 srand((size_t)time(NULL)); for (int i = 0; i< 10; i++) { ...
2019-05-20 21:31:34
294
原创 c语言二级指针与二维数组
一、二维数组的地址不能赋给二级指针的原因int arr[][3] = { { 1,2,3 },{ 4,5,6 },{ 7,8,9 } };int** p = arr;二、指针遍历二维数组int* p1 = arr; for (int i = 0; i < sizeof(arr)/sizeof(arr[0][0]); i++) { printf("%d ",*p1++)...
2019-05-20 15:00:56
1852
原创 c语言字符串的操作
一、代码/** 字符串去空格 */void trimStr(char* str){ int index=0; int readIndex = 0; while (*(str+readIndex)) { if(str[readIndex]!=' '){ str[index++] = str[readIndex++]; ...
2019-05-19 19:25:00
181
原创 c语言二级指针与指针数组
一、代码int main(int argc, const char * argv[]) { int a[] = {1,2,3}; int b[] = {4,5,6}; int c[] = {7,8,8}; int* arr[] = {a,b,c}; int** p = arr; printf("a[0] = %d\n",a[0]); ...
2019-05-19 18:38:05
1570
原创 测试ExecutorService的关闭和终止方法
1.shutdown()public static void main(String[] args) throws InterruptedException { ExecutorService executorService = Executors.newFixedThreadPool(1); Runnable[] runnables = new Runnabl...
2019-05-09 16:20:37
2921
2
转载 Java 8-Lambdas(Notes)
(摘自https://www.oracle.com/technetwork/articles/java/architect-lambdas-part1-2080972.html)1.Type inference.One of the features that some other languages have been touting is the idea of type inferenc...
2019-05-06 15:27:30
225
原创 grpc--demo(参考官网说明看demo)
1.grade配置文件(官网上有gradle及maven的配置说明)plugins { id 'java' id 'com.google.protobuf' version '0.8.8'}group 'com.hgl.dp.io.grpc'version '1.0-SNAPSHOT'sourceCompatibility = 1.8targetCompatibil...
2019-04-24 16:21:08
1285
原创 应用通信协议与序列化协议(区别)
通信协议与序列化协议一、通信协议:如http协议,dubbo协议、websocket协议等二、序列化协议:protobuf协议、json协议、xml等
2019-04-21 19:57:00
1344
转载 java Finalizer陷阱
java Finalizer陷阱java中使用可达性分析来确定对象是否需要回收,即使是不可达的对象,也不是“非死不可”的,这时候他们暂时处于“缓刑”阶段,要真正宣告一个对象死亡,至少要经历两次标记过程:如果对象在进行可达性分析后发现没有与GC Roots相连接的引用链,那它将会被第一次标记并且进行一次筛选,筛选的条件是此对象是否有必要执行finalize()方法。当对象没有覆盖finalize(...
2019-04-19 10:52:15
319
转载 java 匿名内部类对象持有外部类对象的引用
转载自:https://www.jianshu.com/p/9335c15c43cf/** * @author hgl * @data 2019年1月10日 * @description 接口 */public interface TestInterface { public void innerMethod();}/** * @author hgl * @data 20...
2019-01-10 14:59:20
4322
转载 银行家算法(java实现)--避免进程死锁
public class Banker {/* * 资源的种类 */private final int RESOUCE_NUM = 3;/* * 进程的数量 */private final int PROCESS_NUM = 3;/* * 可获取每种资源的数量的数组 */private int[] available = new int[RESOUCE_NUM];/...
2018-12-09 13:46:56
1477
原创 spring boot 集成springmvc和mybatis
一、项目结构(maven项目)二、pom文件<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven....
2018-11-07 18:06:16
399
原创 mybatis 查询返回结果封装成map而不是
一、背景最近项目中有个导出excel缓慢,数据量也不是很大,每次限制5000条,sql查询很快,问题出现在把数据库中的原因代号转化为字符串的过程。原代码是把查询出来的结果进行for循环,然后一个个的根据reasonId去查数据库,再把结果set到bean中,导致非常缓慢。二、优化策略优化的策略是一次把结果查询出来,然后存储到map中,以reasonId作为key,reasonBean作为va...
2018-11-05 14:49:24
4478
原创 B-Tree的查找、插入和删除(java实现)
一、java Beanpackage com.hgldp.web.pojo;import java.util.LinkedList;/** * @author hgl * @data 2018年11月3日 * @description b-tree 结点 */public class BSTNode { /* * 关键字数量 */ private int keyn...
2018-11-04 22:06:08
881
1
原创 平衡二叉树的插入(java实现)
/** * @author hgl * @data 2018年9月24日 * @description 平衡二叉树的结点 */public class BSTNode { public int data;//数据 public int bf;//结点的平衡因子 public BSTNode lchild;//左孩子 public BSTNode rchild;//右孩子...
2018-10-15 22:06:02
430
转载 Mybatis foreach的参数(Map)
一、平时用到List、array[数组]的情况比较多,工作中有一个需求,想到可以用map来传值,而且比较方便,把我的场景分享给大家。二、 场景1:insert时,列的数量和名称是不固定的,需要动态的处理,这种需求感觉用map传值比较方便。 场景2: 1 单元测试:@RunWith(SpringJUnit4ClassRunner.class)//junit整合spring的测试//...
2018-09-02 17:09:11
18739
2
转载 HashMap源码窥探(jdk 7)
一、在实际开发中,使用hashMap的场景较多,也需要了解底层的实现,能更好的使用它,个人理解,如有不妥,望指正。二、HashMap的数据结构 HashMap的数据结构是一个数组,数组中存储的是entry,而entry是一个单向的链表结构,entry中的元素包括(key,value,hsah,entry),entry代表的是下一个entry。为什么会采用这种结构?个人理解是HashMap...
2018-08-26 17:30:53
190
原创 二叉排序树删除某个结点保持排序树特性的Java算法实现
一、二叉排序树的定义 二叉排序树是一棵空树;或者是具有下列性质的二叉树: 1)若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值; 2)若它的右子树不空,则右子树上所有结点的值均大于它的根结点的值; 3)它的左右子树也分别为二叉排序树 图 二、二叉排序树删除一个结点的情况讨论 待删除的结点记为 p,父结点为f,且p为f的左子树 ...
2018-08-19 10:38:20
2734
2
原创 快速排序(Java)
一、概念 快速排序(Quick Sort)是对起泡排序的一种改进。它的基本思想是,通过一趟排序将待排序的记录分割成独立的两部分,其中一部分记录的关键字均比另一部分记录的关键字小,则可分别对这两部分记录继续进行排序,以达到整个序列有序。 二、图解 三、Java代码package com.hgldp.web;import java.util.Arrays;p...
2018-07-07 17:38:07
466
原创 命令模式(三)
11 让遥控器具备“Party模式” 遥控器按下一个按钮,就可以打开电灯,打开CD等等,同时具备一键撤销功能。厂商类:/** * @author hgl * @data 2018年5月20日 * @description 音响 (示例四) */public class Stereo { private String message; public Stereo...
2018-05-20 21:01:15
219
原创 命令模式(二)
10 为遥控器加上撤销功能/** * @author hgl * @data 2018年5月20日 * @description 电灯 (示例三) */public class NewLight { private String message; public NewLight(String message) { super(); ...
2018-05-20 17:38:11
148
原创 命令模式(一)
1 需求 设计一个家电自动化遥控器的API * 这个遥控器一共有7个可编程的插槽(每个都可以指定到一个不同的家电装置),每个插槽都有对应的开关按钮。这个遥控器还具备一个整体的撤销按钮。 * 有一组Java类,这些类是由多家厂商开发出来的,用来控制家电自动化装置,如电灯泡,风扇,热水器和音响等。 * 创建一组控制遥控器遥控的API,让每个插槽都能够控制一个或一组装置。注意:能够控制目前...
2018-05-20 15:09:11
598
db2 jdbc连接时如何指定字符编码
2019-10-11
tomcat 通过server.xml部署项目访问出错
2018-04-10
TA创建的收藏夹 TA关注的收藏夹
TA关注的人