add comment

This commit is contained in:
xusun000
2021-11-29 17:25:25 +08:00
parent 57fbb00ad6
commit 3f27972d34
3 changed files with 13 additions and 10 deletions

View File

@@ -3,15 +3,15 @@
#include<string.h>
void min_integer(int a[], int n) {
int* tmp = (int*)malloc(4 * n);
memset(tmp, 0, n * 4);
int* tmp = (int*)malloc(4 * n);//动态分配数组空间
memset(tmp, 0, n * 4);//空间置0
int i;
for (i = 0;i < n;i++) {
if (a[i] <= n && a[i] > 0) {
tmp[a[i] - 1] = 1;
tmp[a[i] - 1] = 1;//将对应map位的元素置为1
}
}
for (i = 0;i < n;i++) {
for (i = 0;i < n;i++) {//遍历得到第一个缺失的正整数
if (tmp[i] == 0)break;
}
printf("%d", i + 1);

View File

@@ -9,6 +9,7 @@ void printArr(int a[], int n) {
}
int Partition(int A[], int low, int high) {
//快速排序
int pivot = A[low]; //选取第一个作为枢轴
while (low < high) {
while (low < high && A[high] >= pivot)
@@ -24,7 +25,7 @@ int Partition(int A[], int low, int high) {
void QuickDivideSort(int A[], int low, int high, int n) {
if (low < high) {
int pivot = Partition(A, low, high);
if (pivot < n / 2)
if (pivot < n / 2)//划分出n/2的位置
QuickDivideSort(A, pivot + 1, high, n);
else
QuickDivideSort(A, low, pivot - 1, n);

View File

@@ -1,5 +1,6 @@
#include<stdio.h>
#include <stdlib.h>
typedef struct node {
char data[10];
struct node* left, * right;
@@ -11,15 +12,16 @@ void midQuation(BTree* T) {
bool flag = false;
flag = (t == '+' || t == '-' || t == '*' || t == '/');
if (flag)printf("(");
if (T->left != NULL)midQuation(T->left);
for (int i = 0;T->data[i] != '\0';i++) {
printf("%c", T->data[i]);
}
if (T->right != NULL)midQuation(T->right);
if (T->left != NULL)midQuation(T->left);//左子树递归
printf("%c", T->data[0]);//打印当前节点
if (T->right != NULL)midQuation(T->right);//右子树递归
if (flag)printf(")");
}
}
/**
* 创建二叉树
*/
void createTree(BTree* node, char c[], int pos, int length) {
if (pos < length) {//填入数据
node->data[0] = c[pos];