程序片段(01):01.二维数组.c

内容概要:二维数组

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. //01.关于栈内存开辟数组:
  4. // 诀窍:将所有维度的数组看做为一维数组,
  5. // 然后再采用指向该数组当中首个元素的指针(变量|常量)
  6. // 秘诀:原始数组数组名称替换法:
  7. // 就可以直接得到指向数组的指针(将数组名称-->替换为-->(*pArr))
  8. // 特点:指针变量可以不用最高维度,
  9. // 但是类型转换必须加上表示最高维度的中括号!
  10. int main01(void)
  11. {
  12. //int arrArr[3][4];//位于栈内存:
  13. int * p1 = (int []) {0};//一维数组-->栈上开辟
  14. int(*p2)[4] = (int[][4]) { 0 };//二维数组-->栈上开辟
  15. int(*p3)[3][4] = (int[][3][4]) { 0 };//三维数组-->栈上开辟
  16. system("pause");
  17. }
  18. //02.堆栈开辟指针数组以及指针数组的回收顺序!
  19. // 1.防止内存泄露现象的产生
  20. // 2.动态数组可以按照静态数组的方式进行访问!
  21. int main02(void)
  22. {
  23. //堆内存开辟数组!
  24. int ** pp = calloc(3, sizeof(int *));//分配指针数组[一级指针数组!]
  25. for (int i = 0; i < 3; ++i)
  26. {
  27. pp[i] = malloc(4 * sizeof(int));//每个指针必须分配内存!
  28. }
  29. int num = 0;
  30. for (int i = 0; i < 3; ++i)
  31. {
  32. for (int j = 0; j < 4; ++j)
  33. {
  34. //&pp[i]-->pp+i
  35. //&pp[i][j]-->*(pp+i)+j
  36. //pp[i]-->*(pp+i)
  37. //pp[i][j]-->*(*(pp+i)+j);
  38. //printf("%4d", pp[i][j] = num++);
  39. printf("%4d", *(*(pp + i) + j));
  40. }
  41. printf("\n");
  42. }
  43. //严格注意堆内存当中数组的回收顺序!
  44. for (int i = 0; i < 3; ++i)
  45. {
  46. free(pp[i]);//先回收一级指针所指向的内存块儿-->防止堆内存泄露
  47. }
  48. free(pp);//再释放指针数组
  49. system("pause");
  50. }
  51. //03.栈上开辟二维数组:
  52. // 注:在进行栈内存的类型转换的时候,需要一个准确的数组!
  53. int main03(void)
  54. {
  55. //栈上开辟二维数组
  56. int(*p)[4] = (int[3][4]) { 0 };//栈上开辟二维数组,自动回收
  57. int num = 0;
  58. for (int i = 0; i < 3; ++i)
  59. {
  60. for (int j = 0; j < 4; ++j)
  61. {
  62. printf("%3d", p[i][j] = num++);
  63. }
  64. printf("\n");
  65. }
  66. system("pause");
  67. }
  68. //04.分块儿数组的逐级回收特点!
  69. int main04(void)
  70. {
  71. //分块儿内存切忌要逐级进行内存回收!
  72. int(*pArr)[4] = malloc(3 * 4 * sizeof(int));//堆内存:呈线性存储的二维数组
  73. int num = 0;
  74. for (int i = 0; i < 3; ++i)
  75. {
  76. for (int j = 0; j < 4; ++j)
  77. {
  78. printf("%3d \n", pArr[i][j] = num++);
  79. }
  80. printf("\n");
  81. }
  82. free(pArr);//根据指向堆内存的连续存储的二维数组指针,进行堆内存二维数组的回收操作!
  83. system("pause");
  84. }

程序片段(02):01.函数指针.c

内容概要:函数指针

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <Windows.h>
  4. void runmsg()
  5. {
  6. MessageBoxA(0, "您好!", "天朝城管的全家!", 0);
  7. }
  8. void print()
  9. {
  10. printf("%s, %s \n", "您好!", "天朝城管的全家!");
  11. }
  12. //01.严格区分函数指针变量和函数指针常量:
  13. // 函数名的本质:函数指针常量,存储的是代码区函数实体的入口点!
  14. // 函数指针的本质:存储函数指针常量的数据|存储代码区函数实体的入口点
  15. // 通过修改函数指针变量所存储的入口点,让函数指针变量可以调用
  16. // 代码区当中不同的函数实体,从而实现改变函数行为的现象!
  17. //02.对函数名的几种操作:
  18. // &funName--funName--*funName
  19. //注:这几种方式所得到的值相同,都是同一个函数实体的入口点地址!
  20. // 区分函数声明入口点地址和函数调用地址!
  21. int main01(void)
  22. {
  23. //函数指针变量:自己存储与数据区当中,只是存储了代码区的入口点(函数指针常量)
  24. //runmsg = runmsg;//函数名的本质:函数指针常量,存储的是代码区函数体的入口点儿
  25. void(*pFun)() = runmsg;//通过函数指针变量存储函数指针产量的值|存储代码区函数实体的调用地址
  26. pFun();//通过函数指针变量实现函数的间接调用
  27. pFun = print;//修改函数指针变量所存储的函数指针常量,从而实现调用行为的改变
  28. pFun();
  29. printf("%p, %p, %p \n", &runmsg, runmsg, *runmsg);
  30. printf("%p \n", print);
  31. system("pause");
  32. }
  33. //03.对于代码区而言:
  34. // 1.函数指针有类型之分-->函数指针声明格式的类型说明!
  35. // 2.对函数名的几种取值操作所得到的值的性质一样
  36. int main02(void)
  37. {
  38. printf("%p, %p, %p \n", &runmsg, runmsg, *runmsg);
  39. //对于代码区而言,函数指针有类型区分
  40. //&runmsg = runmsg;//编译器原理:获取函数指针的地址,和函数地址一样
  41. //*runmsg = *(&runmsg)=runmsg
  42. system("pause");
  43. }

程序片段(03):01.DllInject.c

内容概要:非法调用

  1. //moveto(int z, int x, int y);//跨点函数:所跨越的维度为三维
  2. _declspec(dllexport)void main()
  3. {
  4. void(*pFun)(void) = 0x0134110E;//声明一个函数指针变量,用于间接调用函数实体
  5. pFun();//调用
  6. }

程序片段(04):01.数组名.c+02.二维数组.c

内容概要:数组名作为函数参数

  1. ///01.数组名.c
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. //数组名作为函数的参数,会退化为指针
  5. void run01(int a[5])//一维数组没有副本机制,作为参数退化为一级指针
  6. {
  7. printf("\n run=%d", sizeof(a));//大小是4
  8. a = a + 1;//数组名可以进行改变,因为已经变为了指针变量的类型
  9. //int b[5];
  10. //b = b + 1;
  11. }
  12. void run02(int *p)//一位数组名作为该函数的参数同样会退化为一级指针,所以这里采用一级指针进行接收
  13. {
  14. for (int i = 0; i < 5; i++)
  15. {
  16. printf("\n %d", p[i]);
  17. }
  18. }
  19. void rev(int *p, int length)
  20. {
  21. //指针法,由于下标,表现对指针的熟练度
  22. for (int *phead = p, *pback = p + length - 1; phead < pback; phead++, pback--)
  23. {
  24. int temp = *phead;
  25. *phead = *pback;
  26. *pback = temp;
  27. }
  28. }
  29. void show(int *p, int length)//一位数组名作为函数的参数进行传递会自动退化为一级指针
  30. {
  31. for (int i = 0; i < length; i++)
  32. {
  33. printf("\n %d", p[i]);
  34. }
  35. }
  36. void main01()
  37. {
  38. int a[5] = { 1,2,3,4,5 };
  39. //a=1;
  40. printf("%d", sizeof(a));
  41. run02(a);
  42. system("pause");
  43. }
  44. void main02()
  45. {
  46. int a[5] = { 1,2,3,4,5 };
  47. int *p = (int[]){ 1, 2, 3, 4, 5, 6 };
  48. rev(a, 5);
  49. show(a, 5);
  50. printf("\n\n");
  51. rev(p, 6);
  52. show(p, 6);
  53. system("pause");
  54. }
  1. ///02.二维数组.c
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. //01.在C语言当中的static关键字用途:
  5. // 限定(变量|函数)只能作用于本文件;
  6. // 相当于缩小全局变量的作用范围!
  7. //02.数组作为函数形参的退化指针规律:
  8. // 将所有数组看做为一维数组;
  9. // 那么指向该数组当中首个元素的指针(变量|常量)
  10. // 的指针就是该数组所退化成为的指针
  11. //03.如何快速定位堆上数组的解析方式?
  12. // 开辟几位数组就采用指向几位数组的指针进行解析!
  13. // 至于指针的声明格式采用上一个说明规律!
  14. static void show(int(*pArr)[4])
  15. {
  16. printf("run: sizeof(pArr) = %d \n", sizeof(pArr));
  17. //pArr = pArr + 1;//变量指针:数组名作为函数指针将退化成为变量指针!
  18. int res = 0;
  19. for (int i = 0; i < 3; ++i)
  20. {
  21. for (int j = 4; j < 4; ++j)
  22. {
  23. printf("%3d", res += pArr[i][j]);
  24. }
  25. printf("\n");
  26. }
  27. printf("平均分 = %d \n", res /= 3);//统计所用总分/人数
  28. }
  29. void search(int(* pArr)[4], int ifind)
  30. {
  31. for (int i = 0; i < 3; ++i)
  32. {
  33. for (int j = 0; j < 4; ++j)
  34. {
  35. printf("%3d", pArr[i][j]);
  36. }
  37. printf("\n");
  38. }
  39. }
  40. void get(int(*pArr)[4])
  41. {
  42. int flag = -1;
  43. for (int i = 0; i < 3; ++i)
  44. {
  45. flag = 1;
  46. for (int j = 0; j < 4; ++j)
  47. {
  48. if (*(*(pArr + i) + j) < 60)
  49. {
  50. flag = 0;
  51. break;
  52. }
  53. }
  54. if (flag)
  55. {
  56. printf("%d号学生的成绩及格! \n", i);
  57. }
  58. else
  59. {
  60. printf("%d号学生的成绩不及格! \n", i);
  61. }
  62. }
  63. }
  64. //04.关于数组内存的开辟方式:
  65. // 1.按照所属内存区块儿:
  66. // 栈内存+堆内存
  67. // 2.按照解析方式:
  68. // 标准二维数组+分块数组模型
  69. // 注:位于栈内存的数组都是连续存储的,位于堆内存的数组视情况而定(指针决定对该片儿内存的解析方式)
  70. int main03(void)
  71. {
  72. int arrArr[3][4] = { 89, 78, 55, 71, 82, 54, 53, 70, 100, 98, 99, 91 };
  73. //这样分配的二维数组是位于堆内存的连续存储空间(整体连续),而采用二级指针所指向的数组是非整体连续的
  74. int(*pArr)[4] = (int[][4]) { 89, 78, 65, 71, 82, 94, 93, 70, 100, 98, 99, 91 };//栈上的二维数组
  75. show(pArr);
  76. search(pArr, 2);
  77. get(pArr);
  78. system("pause");
  79. }

程序片段(05):01.函数指针.c

内容概要:函数指针强化

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. //01.在C语言当中,当形参位于函数声明位置的时候:
  4. // 可以不用指明形参名称;但是函数实现的时候需要指明形参名称!
  5. int add(int, int);
  6. int add(int a, int b)
  7. {
  8. return a + b;
  9. }
  10. int sub(int a, int b)
  11. {
  12. return a - b;
  13. }
  14. int mul(int a, int b)
  15. {
  16. return a * b;
  17. }
  18. int divv(int a, int b)
  19. {
  20. return a / b;
  21. }
  22. int getmin(int a, int b)
  23. {
  24. return a < b ? a : b;
  25. }
  26. int getmax(int a, int b)
  27. {
  28. return a > b ? a : b;
  29. }
  30. //02.采用函数指针作为形参可以实现固化接口的作用
  31. // 固化接口+动化逻辑!
  32. void op(int(*pFun)(int, int), int a, int b)
  33. {
  34. printf("%d \n", pFun(a, b));
  35. }
  36. //02.只要作为声明的格式,就可以进行函数形参的省略!
  37. // 1.区分函数调用和读取函数指针常量所存储的函数入口点地址
  38. // 2.对于函数指针变量没有自变的说法,因为毫无意义!
  39. //03.区分函数指针变量和函数指针变量的类型!
  40. // 诀窍:挖取函数指针变量声明格式当中的函数变量名就是
  41. // 该函数指针的具体类型!
  42. int main01(void)
  43. {
  44. //错误的定义方式,因为类型不匹配
  45. //int(*pFun)(int, int) = add(1, 2);//不行:函数调用-->返回结果-->被当做函数调用地址!-->错误现象
  46. //参数名可以省略,声明的结构
  47. int(*pFun)(int, int) = add;
  48. //p1++;//函数指针变量,没有变的说法!
  49. //p2++;
  50. //p3 + n;
  51. //int(*pFun)(int, int);//函数指针
  52. //int (*)(int, int)//函数指针的类型
  53. int(* get() )(int, int);//一个返回值为函数指针,参数为void类型的函数常量指着
  54. //难度解析:规律剖析
  55. // 原始:int(*get(int(*y)(int, int), double))(int, int);
  56. // 剖析:int(* get( int (*y)(int, int), double ) )(int, int)
  57. // 解析:一个返回值为函数指针(int (*)(int, int)),参数为函数指针(int(*y)(int, int))和双精度浮点型(double)的函数指针常量
  58. // 特点:函数实现的时候,所有形参必须具备形参名称!
  59. // 作为函数的返回值类型声明不需要进行名称说明!
  60. // 拓展:指向该函数指针的函数指针变量声明格式
  61. // int (*(*pFun)(int(*y)(int, int), double))(int, int)-->该函数指针常量所对应的函数指针变量类型
  62. // int (* (* const pFun)(int(*y)(int, int), double))(int, int)-->该函数指针常量所对应的函数指针类型
  63. system("pause");
  64. }

程序片段(06):函数指针数组.c

内容概要:函数指针数组与指向函数指针的指针

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int getmin(int a, int b)
  4. {
  5. return a < b ? a : b;
  6. }
  7. int getmax(int a, int b)
  8. {
  9. return a > b ? a : b;
  10. }
  11. int add(int a, int b)
  12. {
  13. return a + b;
  14. }
  15. int sub(int a, int b)
  16. {
  17. return a - b;
  18. }
  19. int mul(int a, int b)
  20. {
  21. return a * b;
  22. }
  23. int divv(int a, int b)
  24. {
  25. return a / b;
  26. }
  27. //01.数组格式的规律:
  28. // 在数组所存储元素的定义格式基础上,在数组元素名称的末尾添加中括号[数组元素个数];
  29. // 该数组元素名称成为数组名称
  30. //02.函数指针的规律:
  31. // 在函数声明格式的基础之上,将函数名称直接替换为(*pFun),那么pFun
  32. // 就是指向该函数的函数指针(*pFun)-->函数变量指针;(* const pFun)函数常量指针,如同数组名
  33. int main01(void)
  34. {
  35. //int a;
  36. //int a[10];
  37. //int *p;
  38. //int *arrP[10];
  39. int(*funP)(int, int) = getmax;
  40. //函数指针数组
  41. int(*funPArr[10])(int, int) = { getmin, getmax, add, sub, mul, divv };
  42. //funPArr是函数指针数组的数组名,二级函数指针可以直接存储一个一级函数指针数组的首地址
  43. //int (**funP1)(int, int)<=>int (*funP2[6])(int, int)
  44. // funP1是二级函数变量指针+funP2是二级函数常量指着
  45. //注:凡是设计数组名都是常量指针
  46. //printf("%d \n", sizeof(funP1));
  47. //funP2 = funP1;//funP2是一个常量指针
  48. for (int i = 0; i < 6; ++i)
  49. {//索引遍历
  50. //printf("%d \n", funPArr[i](1, 2));//funPArr[i]代表函数指针变量本身
  51. printf("%d \n", (*(funPArr + i))(1, 2));//funPArr[i]=>*(funPArr + i)
  52. }
  53. for (int(**funPP)(int, int) = funPArr; funPP < funPArr + 6; ++funPP)
  54. {
  55. printf("%d", (*funPP)(100, 10));
  56. }
  57. system("pause");
  58. }
  59. //03.函数指针相关概念!
  60. //int (*funP)(int, int)
  61. // funP是一级函数变量指针
  62. //int (*funPArr[10])(int, int)
  63. // funPArr是二级函数常量指针
  64. //int (**funPP)(int, int)
  65. // funPP是二级函数变量指针
  66. //04.所有数组的推导特点
  67. //int a;
  68. //int a[10];
  69. //int * a;
  70. //int * p1;
  71. //int * p1[10];
  72. //int ** p1;
  73. int main02(void)
  74. {
  75. //int intArr[6] = { 1, 2, 3, 4, 5, 6 };
  76. int(*funPArr[6])(int, int) = { getmin, getmax, add, sub, mul ,divv };
  77. //intArr和funPArr都属于常量指针:作为数值而言,都是存储与代码区符号表当中
  78. //int * p = (int []){ 1, 2, 3, 4, 5, 6 }//栈上开辟一个一维数组
  79. //int(**funPP)(int, int);//二级函数变量指针,存储函数指针数组的数组名
  80. //int (*[])(int, int);//函数指针数组类型
  81. int(**funPP)(int, int) = (int(*[])(int, int)) { add, sub, mul, div };
  82. for (int i = 0; i < 4; ++i)
  83. {
  84. //printf("%d \n", funPP[i](100, 10));
  85. printf("%d \n",(*(funPP + i))(100, 10));
  86. }
  87. system("pause");
  88. }
  89. int main03(void)
  90. {
  91. int(**funPP)(int, int) = malloc(4 * sizeof(int(*)(int, int)));//在堆内存开辟一个一级函数指针数组
  92. *funPP = add;
  93. *(funPP + 1) = sub;
  94. *(funPP + 2) = mul;
  95. *(funPP + 3) = divv;
  96. for (int i = 0; i < 4; ++i)
  97. {
  98. //printf("%d \n", funPP[i](100, 10));
  99. printf("%d \n", (*(funPP + i))(100, 10));
  100. }
  101. system("pause");
  102. }
  103. //05.变量+变量数组+指向变量的变量:
  104. // 三种形式的推导规律
  105. //int * p;------->int (*funP)(int, int);
  106. //int * p[10];--->int (*funP[10])(int, int);
  107. //int ** pp;----->int (**funPP)(int, int)
  108. //06.typedef的强大作用:
  109. // 某些情况之下的复杂函数指针必须通过typedef进行别名定义!
  110. //int a;
  111. //typedef int a;
  112. //int b[10];
  113. //typedef int b[10];
  114. //double * d;
  115. //typedef double * d;
  116. //int (* funP )(int, int);
  117. //typedef int (*funP)(int, int);
  118. //int (*funP[10])(int, int);
  119. //typedef int (*funP[10])(int, int);
  120. //int (**funPP)(int, int);
  121. //typedef int (**funPP)(int, int);
  122. //typedef终极规律:
  123. // 先定义变量名:类型+变量名
  124. // 再使用前置typedef:于是变量名就成为了类型别名
  125. //注:typedef并不是生产出一个新类型,而是为已有类型领取一个简洁的别名
  126. // 编译后期操作类型-->某些情况之下的复杂函数指针不得不使用typedef关键字
  127. // 进行别名定义!
  128. int main04(void)
  129. {
  130. //a a1;
  131. //b b1;
  132. //d d1;
  133. //p d1 = add;
  134. //px px1 = { add, sub, mul, divv };
  135. //pp pp1 = (px){ add, sub };
  136. //printf("%d \n", sizeof(px1));
  137. system("pause");
  138. }
  139. //07.函数指针终极形式!
  140. // 原始:int(**x(int(*z)(int,int),int,double))(int);
  141. // 返回值:int(** x(int(*z)(int,int),int,double) )(int)
  142. // 形参:int(** x( int(*z)(int, int), int, int ) )(int)
  143. // 解读:
  144. // 函数名:x是一个函数的名称,属于函数常量指针
  145. // 返回值:int(**)(int),是一个函数二级函数指针
  146. // 形参:int (*z)(int, int), int, double,有三个形式参数
  147. // 分别是函数指针类型+int类型+double类型
  148. //注:区分数组指针和函数指针
  149. // 数组指针:
  150. // int arrArr[a][b]-->int (*p)[a][b];
  151. //注:指向N维数组的指针声明规律:
  152. // 只需要将数组名称替换为(*p)
  153. //08.数组指针和函数指针的区别:
  154. // 1.都含有(*p)说明特点
  155. // 2.各自的后续内容不一样:
  156. // 数组指针跟的是中括号!
  157. // 函数指针跟的是小括号!
  158. //注:所有指向数组类型的指针定义绝招!
  159. // 先写出数组的声明格式,再将数组名称替换为(*pArr);
  160. //注:所有指向函数类型的指针定义绝招!
  161. // 先写出函数的声明格式,再将函数名称提花为(*Fun);
  162. int main05(void)
  163. {
  164. int(*funPArr[10])(int, int);
  165. int(*(*pFunPArr)[10])(int, int);//指向函数数组的指针
  166. system("pause");
  167. }

程序片段(07):dialog.cpp

内容概要:PingWindows

  1. #include "dialog.h"
  2. #include <QApplication>
  3. void run()
  4. {
  5. //01.在栈内存当中创建对话框容易自动回收掉!
  6. //Dialog w;
  7. //w.show();
  8. //02.在堆内存当中创建的对话框需要手动回收!
  9. //Dialog * p = new Dialog;
  10. //(*p).show();
  11. //p->show();
  12. //03.同样是在栈内存当中创建的对话框
  13. //Dialog ws[10];
  14. //for (int i = 0; i < 10; ++i)
  15. //{
  16. // ws[i].resize(100, 100);
  17. // ws[i].move(100*i, 100*i);
  18. // ws[i].show();
  19. }
  20. //04.逐个在堆内存当中创建对话框,不会被自动回收掉!
  21. //Dialog * p[10];
  22. //for (int i = 0; i < 10; ++i)
  23. //{
  24. // p[i] = new Dialog;
  25. // p[i]->resize(100, 100);
  26. // p[i]->move(100*i, 100*i);
  27. // p[i]->show();
  28. //}
  29. //5.创建50个位于堆内存当中的对话框
  30. //Dialog *px[5][10];
  31. //for(int i=0;i<5;i++)
  32. //{
  33. // for(int j=0;j<10;j++)
  34. // {
  35. // px[i][j]=new Dailog;
  36. // px[i][j]->resize(100,100);
  37. // px[i][j]->move(100*i,100*j);
  38. // px[i][j]->show();
  39. // }
  40. //}
  41. }
  42. int main(int argc,char *argv[])
  43. {
  44. QApplication a(argc,argv);
  45. //run();
  46. Dialog w;
  47. w.show();
  48. return a.exec();
  49. }

程序片段(08):01.多线程.c

内容概要:函数指针数组与多线程

  1. ///01.多线程.c
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <Windows.h>
  5. #include <process.h>
  6. void run01(void * p)
  7. {
  8. MessageBoxA(0, "1", "1", 0);
  9. }
  10. void run02(void * p)
  11. {
  12. MessageBoxA(0, "2", "2", 0);
  13. }
  14. void run03(void * p)
  15. {
  16. MessageBoxA(0, "3", "3", 0);
  17. }
  18. //01.多线程内容:
  19. // 1.关于模式的不同:
  20. // 单线程模式:只能实现单线程,不能实现多线程
  21. // 多线程模式:技能实现单线程,又能实现多线程
  22. // 2.关于多线程的等待特点:
  23. // 无限等待:-->如同单线程
  24. // 有限等待:-->定时等待!
  25. // 3.多线程情况下的主辅线程特点:
  26. // 主线程进行全局控制
  27. // 辅助线程进行独立控制
  28. // 4.线程句柄数组的使用:管理线程
  29. // 可以实现同时等待多条线程
  30. //02.关于是否需要对栈内存数组进行强制转换的问题:
  31. // 指向数组的指针,无需进行类型转换
  32. // 指向指针的指针,需要进行类型转换
  33. //03.关于多线程的调度问题:
  34. // 需要使用到线程句柄数组进行管理
  35. // WaitForMutipleObjects(arg1,arg2,arg3,arg4);
  36. // arg1:线程句柄个数
  37. // arg2:线程句柄数组名
  38. // arg3:等待单个还是多个?-->竞赛最快的那个!-->可以等待单个!
  39. // arg4:等待时间
  40. int main01(void)
  41. {
  42. //run01(NULL);
  43. //run02(NULL);
  44. //run03(NULL);//-->单线程模式
  45. for (int i = 0; i < 3; ++i)
  46. {
  47. HANDLE hd = _beginthread(run01, 0, NULL);
  48. //WaitForSingleObject(hd, INFINITE);//无限同步等待
  49. WaitForSingleObject(hd, 3000);//有限同步等待!
  50. }
  51. //HANDLE hd[3] = {0};//声明线程句柄数组
  52. //HANDLE * hd = malloc(12);
  53. HANDLE * hd = malloc(3 * sizeof(HANDLE));
  54. //void(*funPArr[3])(void *) = { run01, run02, run03 };//函数指针数组
  55. //采用二级函数变量指针进行指向一个栈内存的函数指针数组
  56. void(**funPP)(void *) = (void(*[])(void *)) { run01, run02, run03 };
  57. for (int i = 0; i < 3; ++i)
  58. {
  59. hd[i] = _beginthread(funPP[i], 0, NULL);
  60. }
  61. //TRUE等待所有线程,false表示等待单个
  62. WaitForMultipleObjects(3, hd, FALSE, INFINITE);//无限等待多个线程结束
  63. //主线程,控制全局
  64. system("pause");//卡顿主线程-->让主线程不要提前执行完毕
  65. }
  66. ////线程既可以同步,也可以异步
  67. ////WaitForSingleObject(hd,300);//3000等待3秒
  68. ////主线程,控制全局
  69. ////WaitForMultipleObjects(3,hd,TRUE,INFINITE);

程序片段(09):01.Alloca.c

内容概要:栈内存分配

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <malloc.h>
  4. //01.关于堆内存开辟四大函数和栈内存开辟单函数:
  5. // 堆内存:malloc-->calloc-->realloc-->_recalloc
  6. // 栈内存:alloca-->位于malloc.h头文件
  7. //注:栈内存没有对应的内存回收函数,堆内存才有对应
  8. // 的内存回收函数!!
  9. int main01(void)
  10. {
  11. int * p = alloca(10 * sizeof(int));//超过栈内存尺寸上限
  12. for (int i = 0; i < 10; ++i)
  13. {
  14. p[i] = i;
  15. }
  16. //free(p);//栈内存没有回收的free();函数
  17. system("pause");
  18. }
  19. void show()
  20. {
  21. int * p = alloca(10 * sizeof(int));//超过栈内存大小
  22. for (int i = 0; i < 10; ++i)
  23. {
  24. p[i] = i;
  25. }
  26. //free(p);//栈内存没有匹配的free函数-->自动回收所属内存
  27. printf("\n");
  28. }
  29. int main02(void)
  30. {
  31. show();
  32. printf("\n\n");//促进内存回收动作的发生
  33. show();//检验栈内存数组的自动回收特点
  34. printf("\n");//注意编译器的优化情况
  35. system("pause");
  36. }

程序片段(10):main.c

内容概要:GccArray

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. //01.GCC支持栈内存的动态数组的实现原理就是
  4. // 位于malloc.h头文件当中的alloca函数!
  5. //02.VC编译器不支持位于栈内存的动态数组!
  6. int main01()
  7. {
  8. printf("Hello world! \n");
  9. //GCC当中的实现原理就是C语言当中的Alloc,但是这种规则不是C语言的标准机试
  10. int num=20;
  11. int a[num];
  12. // a=a;
  13. return 0;
  14. }

程序片段(11):01.Main.c

内容概要:获取参数

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. //01.定义主函数的格式:
  4. // 无形参形式:
  5. // void main(void);
  6. // int main(void);
  7. // 有形参形式:
  8. // void main(int argc, char * args[]);
  9. // int main(int argc, char * args[]);
  10. //02.标准主函数声明格式详解:
  11. // int main(int argc, char * args[], char * envp[]);
  12. // 返回值:int-->体现跨平台特性
  13. // 参数1:argc-->说明了有效参数个数
  14. // 参数2:args-->说明了有效参数列表
  15. // 该字符指针数组当中的第一个字符指针所指向的字符串是当前所运行程序的程序名称(代码区常量池"字符串")
  16. // 该字符指针数组当中的第二个字符指针开始之后的指针表示的是当前程序运行时所指定的附加参数!
  17. // 参数3:表示环境变量列表!
  18. // 一个字符指针描述一个环境变量!
  19. int main01(int argc, char * args[])
  20. {
  21. for (int i = 0; i < argc; ++i)
  22. {
  23. puts(args[i]);
  24. }
  25. system("pause");
  26. }
  27. int main02(int argc, char * args[], char * envp[])
  28. {
  29. printf("%d \n", sizeof(envp));//凡是数组作为函数形参,该数组都将会被退化为指针(统统只会占用4个内存字节!)
  30. //for (int i = 0; i < 100; ++i)
  31. //{
  32. // puts(envp[i]);
  33. //}
  34. char **pp = envp;
  35. while (NULL != *pp)
  36. {
  37. puts(*pp);
  38. ++pp;
  39. }
  40. system("pause");
  41. }

程序片段(12):01.返回.c

内容概要:返回指针

  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <time.h>
  6. //01.对字符数组除了定义并初始化格式之外的字符串赋值方式!
  7. // 必须借助strcpy();函数进行对字符数组的赋值操作!
  8. //注:所以数组的数组名都绝对是一个常量指针!
  9. //02.被掉函数在进行返回指针的时候绝对不能够返回指向栈内存
  10. // 的指针!切忌这一点儿
  11. char * get()
  12. {
  13. char str[100] = { 0 };//栈内存-->字符数组
  14. strcpy(str, "Hello ZhouRuiFu");//为字符数组赋予字符串
  15. printf("%s \n", str);
  16. return str;
  17. }
  18. //03.如何快速定位某个数组的两种形式:
  19. // 1.数组的两种形式:分别用指针形式进行表述
  20. // 普通数组形式-->指向数组的指针
  21. // 指针数组形式-->指向指针的指针
  22. // 2.任何数组都可以用两种形式的指针进行指向!
  23. // 规律总结:针对任何一个维度的数组!
  24. // 普通数组形式-->指向数组的指针:将数组名直接替换为(*arrP)
  25. // 指针数组形式-->指向指针的指针:将数组名以及最高维度直接替换为(*pArr)
  26. int * rungetmin()
  27. {
  28. int * p = calloc(10, sizeof(int));//不会进行自动回收!
  29. time_t te;
  30. unsigned int seed = (unsigned int)time(&te);
  31. srand(seed);
  32. for (int i = 0; i < 10; ++i)
  33. {
  34. printf("%d \n", p[i] = rand() % 100 + 1);
  35. }
  36. int minIndex = 0;
  37. for (int i = 1; i < 10; ++i)
  38. {
  39. if (p[i] < p[minIndex])
  40. minIndex = i;
  41. }
  42. //p + minIndex = &p[minIndex];
  43. //p[minIndex] = *(p + minIndex)
  44. return p + minIndex;
  45. }
  46. //04.printf();函数针对于字符串的解析特点:
  47. // 字符数组:按照字符数组的长度+直接解析到'\0'
  48. // 如果没有解析到'\0'就会出现烫烫...
  49. // 字符指针:解析字符指针所指向的字符串本身+直接解析到'\0'
  50. // 分字符指针所指向的内存空间
  51. // 如果是栈内存和堆内存-->有可能字字符串没有字符串结尾标识符'\0'
  52. // 如果是代码区常量池-->就一定会有字符串结尾标识符'\0'
  53. int main01(int argc, char * args[], char * envp[])
  54. {
  55. char str[100] = { 0 };
  56. strcpy(str, "Hello ZhouRuiFu");
  57. printf("%s \n", str);
  58. system("pause");
  59. }
  60. //05.迷途指针
  61. int main02(int argc, char * argv[], char * envp[])
  62. {
  63. char * p = get();
  64. printf("%s \n", p);//函数在返回指针的时候,不可以返回指向栈内存空间的指针
  65. //因为有可能出现迷途指针
  66. system("pause");
  67. }
  68. int main03(int argc, char * argv[], char * envp[])
  69. {
  70. printf("最小的是%d \n", *rungetmin());
  71. system("pause");
  72. }

程序片段(13):01.函数返回.c

内容概要:函数返回值

  1. //#include <stdio.h>
  2. //#include <stdlib.h>
  3. //
  4. ////01.函数返回值,存在副本机制!
  5. //// 高端CPU:CPU-Cache
  6. //// 底端CPU:MEM-Cache
  7. ////注:副本数据和副本本身!
  8. //// 副本数据不可以获取地址!
  9. //// 副本本身没有操作权限!
  10. //// 原本只是在已经被回收的栈内存!
  11. //02.原本本身-->原本数据-->副本本身-->副本数据!
  12. //int get()
  13. //{
  14. // int a = 5;
  15. // return a;
  16. //}
  17. //
  18. //int main(int argc, char * args[], char * envp[])
  19. //{
  20. // //&get();//get();该操作所对应的返回值位于寄存器高速缓存(高级CPU),(低级CPU)会将内存某段儿空间当中存储
  21. // // 但是同样不允许进行访问操作!-->针对对于数值本身而言就是副本数据!
  22. // printf("%d \n", get());//返回的是副本数据
  23. //
  24. // system("pause");
  25. //}

程序片段(14):Mem.c

内容概要:左值右值与内存实体

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. //01.左右值:
  4. // 左值:
  5. // 1.能够出现在赋值号左边的值
  6. // 2.存在有效的内存实体
  7. // 3.变量
  8. // 右值:
  9. // 1.只能够出现在赋值号右边的值
  10. // 2.不存在有效的内存实体
  11. // 3.常量+表达式(寄存器操作)
  12. int main01(int argc, char * args[], char * envp)
  13. {
  14. int a = 1;
  15. a = a + 10;
  16. a = a + 8;
  17. //a = 3;
  18. //&5;
  19. //&(a + 1);
  20. a = a;//左值都存在内存实体
  21. //右值一般是出于寄存器当中,左值也可以当做右值进行使用
  22. //a + 1 = 3;
  23. system("pause");
  24. }
  25. int main02(int argc, char * args[], char * envp)
  26. {
  27. int a = 10;
  28. int b = 20;
  29. printf("%p, %p \n", &a, &b);
  30. int * p;//指针变量
  31. p = &a;
  32. p = &b;
  33. system("pause");
  34. }
  35. //02.取地址符(&)取值之后的地址数值具备类型特点!
  36. // 指针常量(数值不可变)+常量指针(指向不可变)
  37. int main(int argc, char * args[], char * envp)
  38. {
  39. //int num;//num是左值
  40. //const int num;//num是左值-->存在内存实体-->常变量
  41. const int num = 10;//&num-->int const * num:
  42. *(int *)(&num) = 4;//取地址之后的所得到的地址数值存在类型特点
  43. printf("%d \n", num);
  44. system("pause");
  45. }
  46. int main04(int argc, char * args[], char * envp[])
  47. {
  48. //注意指针类型的统一!
  49. int * p = (int *)3;//地址意义!
  50. *p = 3;
  51. }
  52. //03.区分两个概念:(空类型的指针+空指针)
  53. // 空类型的指针:
  54. // 实质:空类型的指针变量
  55. // 空指针:
  56. // 用于标识指针变量没有任何指向!
  57. int main05(int argc, char * argv[], char * envp[])
  58. {
  59. int * p = NULL;//标识P这个指针变量没有任何指向
  60. int num = 20;
  61. void * pv = &num;//任何类型的地址(只是用于存储地址,但是不知道如何进行解析!)
  62. *(int *)pv;
  63. system("pause");
  64. }

程序片段(15):01内存.c

内容概要:Malloc.Calloc.Realloc

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <malloc.h>
  4. //01.内存五大开辟函数总结:
  5. // 堆内存:
  6. // malloc:不会初始化内存+整体内存尺寸
  7. // calloc:会初始化内存+元素个数+单个内存尺寸
  8. // realloc:不会初始化内存+原始指针+拓展后的总体大小
  9. // _recalloc:会初始化内存+原始指针+拓展后的元素个数+拓展后的单个内存尺寸
  10. // 栈内存:
  11. // alloca:
  12. // 位于malloc.h头文件
  13. // 实际占用的内存总尺寸!
  14. int main01(int argc, char * args[], char * envp)
  15. {
  16. int * p = calloc(25, sizeof(int));//在堆内存开辟一个普通类型的一维数组,会自动初始化为0
  17. printf("%p \n", p);
  18. for (int i = 0; i < 25; ++i)
  19. {
  20. p[i] = i;
  21. }
  22. p = _recalloc(p, 50, sizeof(int));//内存推展+内存清零操作
  23. for (int i = 25; i < 50; ++i)
  24. {
  25. p[i] = i;
  26. }
  27. system("pause");
  28. }
  29. int main02(int argc, char * args[], char * envp)
  30. {
  31. int * p = malloc(10 * sizeof(int));//只能使用这片儿内存
  32. int * p_p = malloc(100);
  33. for (int i = 0; i < 10; ++i)
  34. {
  35. printf("%d \n", p[i] = i);
  36. }
  37. printf("p = %p \n", p);
  38. int * px = realloc(p, 200);//拓展内存,内存不会清零
  39. //返回值为内存地址,拓展成功,后续地址拓展,拓展不成功,将会重新开辟
  40. //原始的内存空间将会自动回收
  41. printf("px= %p \n", px);
  42. for (int i = 0; i < 50; ++i)
  43. {
  44. px[i] = i;
  45. printf("%d \n", px[i]);
  46. }
  47. p[2398787] = 10;
  48. system("pause");
  49. }
  50. int main03(int argc, char * args[], char * envp)
  51. {
  52. //int * p = malloc(100);//malloc不会初始化内存,是整体内存尺寸!
  53. int * p = calloc(25, sizeof(int));//calloc会初始化参内存,个数+尺寸
  54. printf("%p \n", p);
  55. for (int i = 0; i < 25; ++i)
  56. {
  57. p[i] = i;
  58. }
  59. int * p = alloca(123);
  60. system("pause");
  61. }

程序片段(16):01.c

内容概要:Test

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <malloc.h>
  4. //01.在栈内存开辟4个字节的内存空间:
  5. // 注:指针可以指向四区的任何位置,只是指针的类型不一样而已!
  6. int * run()
  7. {
  8. int * p = alloca(4);
  9. *p = 4;
  10. printf("%d \n", *p);
  11. return p;
  12. }
  13. int main01(int argc, char * args[], char * envp[])
  14. {
  15. int * px = run();//返回指向栈内存的指针是错误的做法!
  16. printf("\n");
  17. printf("%d \n", *px);//栈内存在函数出栈之后,立即进行回收!
  18. system("pause");
  19. }
  20. //02.关于多维数组获取其所存储数据的规律:
  21. // 一维数组:一颗星
  22. // 二维数组:两颗星
  23. // 三维数组:三颗星
  24. // N维数组:N颗星...
  25. //注:获取的对象既可以是常量指针,也可以是变量指针!
  26. // 无论常量指针还是变量指针都会被当做数组名对待!
  27. int main02(int argc, char * args[], char * envp[])
  28. {
  29. int arrArr[3][4] = {
  30. 1, 2, 3, 4,
  31. 5, 6, 7, 8,
  32. 9, 10, 11, 12
  33. };//栈内存-->二维数组-->静态初始化!-->代码块儿直接初始化!
  34. //printf("%d \n", arrArr[1][1]);
  35. printf("%d \n", *(arrArr + 1)[1]);//[]的优先级既大于星号("*")又大于点号(".")
  36. printf("%d \n", *(*(arrArr + 1) + 1));
  37. }

程序片段(17):01.Search.c

内容概要:内存模型大数据

  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #define srcPath "E:\\Resource\\TestData\\BigDB\\1EQQBig.txt"
  6. //01.内存架构:文件缓冲于内存当中,将内存用作数据临时缓冲!
  7. char ** g_pp;//全局二级指针变量
  8. int imax = 84357147;//文件总行数
  9. int jmax = 20027;//文件最宽列数
  10. int getimax()
  11. {
  12. int hang = -1;
  13. FILE * pf = fopen(srcPath, "r");
  14. if (NULL == pf)
  15. {
  16. printf("文件读取失败! \n");
  17. return -1;
  18. }
  19. else
  20. {
  21. printf("开始读取! \n");
  22. hang = 0;
  23. while (!feof(pf))//到了文件末尾返回1,没有到文件末尾返回0
  24. {
  25. char readStr[1024] = { 0 };
  26. fgets(readStr, 1024 - 1, pf);//一次读取一样进缓冲区
  27. ++hang;//自增
  28. }
  29. fclose(pf);
  30. }
  31. return hang;
  32. }
  33. int getjmax()
  34. {
  35. int width = -1;
  36. FILE * pf = fopen(srcPath, "r");
  37. if (NULL == pf)
  38. {
  39. printf("文件读取失败! \n");
  40. return -1;
  41. }
  42. else
  43. {
  44. printf("开始读取! \n");
  45. while (!feof(pf))
  46. {
  47. char readStr[30000] = { 0 };
  48. fgets(readStr, 30000 - 1, pf);//每次读取一行的数据到手动字符数组缓冲区当中
  49. int strLength = strlen(readStr);
  50. if (strLength > 50)//字符串筛选
  51. {
  52. //pus(readstr);
  53. if (strLength > width)
  54. {
  55. width = strLength;
  56. }
  57. }
  58. }
  59. fclose(pf);
  60. printf("结束读取! \n");
  61. }
  62. return width;
  63. }
  64. //02.字符串函数的处理特点:
  65. // 不仅可以处理字符数组还可以处理字符指针!
  66. // 兼容C语言当中的两种字符串表示方式!
  67. //加载待读取的文件数据进内存,构建内存架构模型
  68. void loadFromFile()
  69. {
  70. //声明并初始化指针数组
  71. g_pp = (char **)malloc(imax * sizeof(int *));//分配指针数组
  72. memset(g_pp, '\0', imax * sizeof(char *));//清空指针数组
  73. FILE * pf = fopen(srcPath, "r");
  74. if (NULL == pf)
  75. {
  76. printf("文件读取失败! \n");
  77. return -1;
  78. }
  79. else
  80. {
  81. for (int i = 0; i < imax; ++i)
  82. {
  83. char str[1024] = { 0 };
  84. fgets(str, 1024 - 1, pf);//(按行+个数)进行字符串读取
  85. int strLength = strlen(str);
  86. if (strLength < 50)
  87. {
  88. g_pp[i] = malloc((strLength + 1)* sizeof(char));
  89. strcpy(g_pp[i], str);
  90. }
  91. }
  92. fclose(pf);
  93. }
  94. }
  95. //03.在内存架构模型当中执行检索操作!
  96. void search(char * str)
  97. {
  98. if (NULL == g_pp)
  99. return;
  100. for (int i = 0; i < imax; ++i)
  101. {
  102. if (NULL != g_pp[i])
  103. {
  104. char * p = strstr(g_pp[i], str);
  105. if (NULL != p)
  106. {
  107. puts(g_pp[i]);
  108. }
  109. }
  110. }
  111. }
  112. int main01(int argc, char * args[], char * envp[])
  113. {
  114. //printf("imax = %d \n", getimax());
  115. //printf("jmax = %d \n", getjmax());
  116. loadFromFile();
  117. while (1)
  118. {
  119. char str[100] = { 0 };
  120. scanf("%s", str);
  121. search(str);
  122. }
  123. system("pause");
  124. }

程序片段(18):01.KaiFang.c

内容概要:开放数据检索

  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <memory.h>
  5. #include <string.h>
  6. #define srcPath "E:\\Resource\\TestData\\BigDB\\KaiFang.txt"
  7. char ** g_pp;
  8. int imax = 20151574;
  9. int getimax()
  10. {
  11. FILE * pf = fopen(srcPath, "r");
  12. if (NULL == pf)
  13. {
  14. printf("读取文件失败! \n");
  15. return -1;
  16. }
  17. printf("读取文件成功! \n");
  18. int hang = 0;
  19. while (!feof(pf))
  20. {
  21. char readStr[1024] = { 0 };
  22. fgets(readStr, 1023, pf);
  23. ++hang;
  24. }
  25. fclose(pf);
  26. return hang;
  27. }
  28. void loadfromfile()
  29. {
  30. g_pp = (char **)malloc(imax * sizeof(int *));
  31. memset(g_pp, 0, imax * sizeof(char *));
  32. FILE * pf = fopen(srcPath, "r");
  33. if (NULL == pf)
  34. {
  35. printf("打开文件失败! \n");
  36. return -1;
  37. }
  38. printf("打开文件成功! \n");
  39. for (int i = 0; i < imax; ++i)
  40. {
  41. char str[1024] = { 0 };
  42. fgets(str, 1023, pf);
  43. int strLength = strlen(str);
  44. g_pp[i] = (char *)malloc((strLength + 1) * sizeof(char));
  45. if (NULL != g_pp[i])
  46. strcpy(g_pp[i], str);
  47. }
  48. fclose(pf);
  49. }
  50. void searchStr(char * str)
  51. {
  52. char strPath[100] = { 0 };
  53. sprintf(strPath, "E:\\Resource\\TestData\\Test\\%s.txt", str);
  54. FILE * pf = fopen(strPath, "w");
  55. if (NULL == g_pp)
  56. return;
  57. for (int i = 0; i < imax; ++i)
  58. {
  59. if (NULL == g_pp[i])
  60. continue;
  61. char * p = strstr(g_pp[i], str);
  62. if (p == NULL)
  63. continue;
  64. puts(g_pp[i]);
  65. fputs(g_pp[i], pf);
  66. }
  67. fclose(pf);
  68. system(strPath);
  69. }
  70. int main01(void)
  71. {
  72. //printf("imax = %d \n", getimax());
  73. loadfromfile();
  74. printf("内存数据库架构完成! \n");
  75. while (1)
  76. {
  77. char str[100] = { 0 };
  78. scanf("%s", str);
  79. searchStr(str);
  80. }
  81. system("pause");
  82. }

20160212.CCPP体系详解(0022天)的更多相关文章

  1. 20160129.CCPP体系详解(0008天)

    程序片段(01):函数.c+call.c+测试.cpp 内容概要:函数 ///函数.c #include <stdio.h> #include <stdlib.h> //01. ...

  2. 20160226.CCPP体系详解(0036天)

    程序片段(01):01.多线程.c+02.多线程操作.c 内容概要:多线程 ///01.多线程.c #include <stdio.h> #include <stdlib.h> ...

  3. 20160208.CCPP体系详解(0018天)

    程序片段(01):main.c 内容概要:PointWithOutInit #include <stdio.h> #include <stdlib.h> //01.野指针详解: ...

  4. 20160206.CCPP体系详解(0016天)

    代码片段(01):.指针.c+02.间接赋值.c 内容概要:内存 ///01.指针 #include <stdio.h> #include <stdlib.h> //01.取地 ...

  5. 20160205.CCPP体系详解(0015天)

    程序片段(01):01.杨辉三角.c 内容概要:杨辉三角 #include <stdio.h> #include <stdlib.h> #define N 10 //01.杨辉 ...

  6. 20160204.CCPP体系详解(0014天)

    程序片段(01):define.h+data.h&data.c+control.h&control.c+view.h&view.c+AI.h&AI.c+main.c 内 ...

  7. 20160203.CCPP体系详解(0013天)

    程序片段(01):数组.c+02.数组初始化语法.c 内容概要:数组 ///01.数组.c #include <stdio.h> #include <stdlib.h> //0 ...

  8. 20160128.CCPP体系详解(0007天)

    以下内容有所摘取,进行了某些整理和补充 论浮点数的存储原理:float浮点数与double浮点数的二进制存储原理–>阶码 浮点数转二进制 1.整数int类型和浮点数float类型都是占用4个字节 ...

  9. 20160127.CCPP体系详解(0006天)

    程序片段(01):msg.c 内容概要:线程概念 #include <stdio.h> #include <stdlib.h> #include <Windows.h&g ...

随机推荐

  1. Android系统框架构

    写此本文是为了对Android系统框架有一个整体的认识和了解,对于开发和测试人员脑子里要有整体认识以便对工作有所帮助. 进入正题 首先Android系统架构采用了分层架构的思想,共分为四层由上到下分: ...

  2. [LeetCode] Subtree of Another Tree 另一个树的子树

    Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and no ...

  3. ●BZOJ 3309 DZY Loves Math

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3309 题解: 莫比乌斯反演,线筛 化一化式子: f(x)表示x的质因子分解中的最大幂指数 $ ...

  4. UVALive - 3942:Remember the Word

    发现字典里面的单词数目多且长度短,可以用字典树保存 f[i]表示s[i~L]的分割方式,则有f[i]=∑f[i+len(word[j])]   其中word[j]为s[i~L]的前缀 注意字典树又叫前 ...

  5. UVA1658:Admiral

    题意:给定一个有向带权图,求两条不相交(无公共点)的路径且路径权值之和最小,路径由1到v 题解:这题的关键就在于每个点只能走一遍,于是我们想到以边换点的思想,用边来代替点,怎么代替呢? 把i拆成i和i ...

  6. 51 nod 1405 树的距离之和

    1405 树的距离之和 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题   给定一棵无根树,假设它有n个节点,节点编号从1到n, 求任意两点之间的距离(最短路径)之 ...

  7. 【TCP网络协议问题】

    题目描述 在如今的网络中,TCP 是一种被广泛使用的网络协议,它在传输层提供了可靠的通信服务.众所周知,网络是存在时延的,例如用户先后向服务器发送了两个指令 op1 和 op2,并且希望服务器先处理指 ...

  8. bzoj4011[HNOI2015]落忆枫音 dp+容斥(?)

    4011: [HNOI2015]落忆枫音 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1125  Solved: 603[Submit][Statu ...

  9. Delphi7通过SendMessage来实现默认打印机的切换

    具体代码 procedure SetDefaultPrinter(NewDefPrinter: string); var ResStr: array[0..255] of Char; begin St ...

  10. WebDNN:Web浏览器上最快的DNN执行框架

    WebDNN:Web浏览器上最快的DNN执行框架 为什么需要WebDNN? 深层神经网络(DNN)在许多应用中受到越来越多的关注. 然而,它需要大量的计算资源,并且有许多巨大的过程来设置基于执行环境的 ...