摘要: 指针的值作为条件比较,必须确保指针指向的地址存在。 一旦在条件语句中使用了空指针,编译器不会报错,但执行程序就会出现异常,且这种bug很难发现。 阅读全文
posted @ 2022-01-11 00:30 吕辉 阅读(60) 评论(0) 推荐(0)
摘要: 二叉树的抽象数据类型 1 typedef struct Node 2 { 3 char data; 4 struct Node* Lchild; 5 struct Node* Rchild; 6 }BTNode; 按层次非递归遍历 1 void LevelOrder(BTNode* A) 2 { 3 阅读全文
posted @ 2022-01-10 13:57 吕辉 阅读(42) 评论(0) 推荐(0)
摘要: 二叉树的抽象数据类型 1 typedef struct Node 2 {/*二叉树*/ 3 char data; 4 struct Node* Lchild; 5 struct Node* Rchild; 6 }BTNode; 先序遍历 1 void PreOrder(BTNode* A) 2 {/ 阅读全文
posted @ 2022-01-10 00:24 吕辉 阅读(65) 评论(0) 推荐(0)
摘要: 二叉树的抽象数据类型: 1 typedef char DataType; 2 typedef struct Node 3 { 4 DataType data; 5 struct Node* Lchild; 6 struct Node* Rchild; 7 }BTNode;//Binary Tree 阅读全文
posted @ 2022-01-08 23:57 吕辉 阅读(45) 评论(0) 推荐(0)
摘要: 魔方阵是一个古老的智力问题,它要求在一个 N * N 的方阵中填入 1~N²的数字( N 要求为奇数),使得每一行、每一列、每条对角线的累加和都相等。 1 #define _CRT_SECURE_NO_WARNINGS 2 #include <stdio.h> 3 #include <stdlib. 阅读全文
posted @ 2022-01-03 23:29 吕辉 阅读(280) 评论(0) 推荐(0)
摘要: 数组边界问题通常可以用取余来搞定 阅读全文
posted @ 2022-01-03 22:52 吕辉 阅读(30) 评论(0) 推荐(0)
摘要: 结点结构(扩展线性链表) 1 typedef char AtomType; 2 enum ElemTag { ATOM, LIST }; 3 4 typedef struct GLNode 5 {//扩展的线性链表存储结构 6 ElemTag tag; 7 8 union 9 { 10 AtomTy 阅读全文
posted @ 2022-01-03 14:17 吕辉 阅读(144) 评论(0) 推荐(0)
摘要: 1. C 不允许返回一个完整的数组作为函数的参数。但是可以通过指定不带索引的数组名来返回一个指向数组的指针。 2. C 不支持在函数外返回局部变量的地址,除非定义局部变量为 static 变量。 阅读全文
posted @ 2022-01-01 21:20 吕辉 阅读(105) 评论(0) 推荐(0)
摘要: 1 #define _CRT_SECURE_NO_WARNINGS 2 #include <stdio.h> 3 #include <stdlib.h> 4 5 typedef struct node 6 { 7 int row; 8 int col; 9 int value; 10 struct 阅读全文
posted @ 2021-12-31 20:11 吕辉 阅读(183) 评论(0) 推荐(0)
摘要: 1.结构体变量名代表的是整个集合本身,作为函数参数时传递的整个集合,也就是所有成员,而不是像数组一样被编译器转换成一个指针。 2.如果结构体成员较多,尤其是成员为数组时,传送的时间和空间开销会很大,影响程序的运行效率。所以最好的办法就是使用结构体指针,这时由实参传向形参的只是一个地址,非常快速。 阅读全文
posted @ 2021-12-31 12:18 吕辉 阅读(519) 评论(0) 推荐(0)