算法 - 查找算法(顺序、折半、红黑树、AVL树、B+树、散列)
查找
顺序查找
查找算法原理:
顺序查找是一种简单的查找方法,从数组的第一个元素开始,依次比较每个元素,直到找到目标元素或者数组结束为止。
实现步骤:
- 从数组的第一个元素开始。
- 逐一比较数组中的元素与目标值。
- 如果找到目标值,返回其索引。
- 如果遍历完整个数组仍未找到,返回-1。
C语言代码:
#include <stdio.h>int sequential_search(int arr[], int n, int target) {for (int i = 0; i < n; i++) {if (arr[i] == target) {return i;}}return -1;
}int main() {int arr[] = {2, 4, 6, 8, 10};int target = 6;int n = sizeof(arr) / sizeof(arr[0]);int result = sequential_search(arr, n, target);if (result != -1) {printf("Element found at index %d\n", result);} else {printf("Element not found\n");}return 0;
}
代码解释:
int sequential_search(int arr[], int n, int target)
: 定义顺序查找函数,参数为数组、数组长度和目标值。for (int i = 0; i < n; i++)
: 遍历数组。if (arr[i] == target)
: 如果找到目标值。return i
: 返回目标值的索引。return -1
: 如果未找到目标值,返回-1。
折半查找(也称二分查找)
查找算法原理:
折半查找是一种在有序数组中查找目标值的高效方法。它通过不断将查找范围减半,直到找到目标值或范围为空为止。
实现步骤:
- 确定查找范围的起始和结束索引。
- 计算中间索引。
- 比较中间元素与目标值。
- 如果中间元素等于目标值,返回其索引。
- 如果中间元素小于目标值,缩小查找范围至右半部分。
- 如果中间元素大于目标值,缩小查找范围至左半部分。
- 重复上述步骤直到找到目标值或范围为空。
C语言代码:
#include <stdio.h>int binary_search(int arr[], int n, int target) {int left = 0, right = n - 1;while (left <= right) {int mid = left + (right - left) / 2;if (arr[mid] == target) {return mid;}if (arr[mid] < target) {left = mid + 1;} else {right = mid - 1;}}return -1;
}int main() {int arr[] = {2, 4, 6, 8, 10};int target = 6;int n = sizeof(arr) / sizeof(arr[0]);int result = binary_search(arr, n, target);if (result != -1) {printf("Element found at index %d\n", result);} else {printf("Element not found\n");}return 0;
}
代码解释:
int binary_search(int arr[], int n, int target)
: 定义二分查找函数,参数为数组、数组长度和目标值。int left = 0, right = n - 1
: 初始化左右索引。while (left <= right)
: 当查找范围有效时。int mid = left + (right - left) / 2
: 计算中间索引。if (arr[mid] == target)
: 如果找到目标值。return mid
: 返回目标值的索引。if (arr[mid] < target)
: 如果中间元素小于目标值。left = mid + 1
: 调整左索引。else
: 如果中间元素大于目标值。right = mid - 1
: 调整右索引。return -1
: 如果未找到目标值,返回-1。
分块查找
查找算法原理:
分块查找将数据分成若干块,并在每块中进行线性查找。首先找到目标值可能所在的块,然后在该块中进行顺序查找。
实现步骤:
- 将数据分成若干块。
- 在块索引中找到目标值可能所在的块。
- 在该块中进行顺序查找。
C语言代码:
#include <stdio.h>int block_search(int arr[], int n, int target, int block_size) {int block_count = (n + block_size - 1) / block_size;for (int i = 0; i < block_count; i++) {int start = i * block_size;int end = start + block_size;if (end > n) end = n;if (arr[end - 1] >= target) {for (int j = start; j < end; j++) {if (arr[j] == target) {return j;}}return -1;}}return -1;
}int main() {int arr[] = {2, 4, 6, 8, 10, 12, 14, 16, 18};int target = 10;int n = sizeof(arr) / sizeof(arr[0]);int block_size = 3;int result = block_search(arr, n, target, block_size);if (result != -1) {printf("Element found at index %d\n", result);} else {printf("Element not found\n");}return 0;
}
代码解释:
int block_search(int arr[], int n, int target, int block_size)
: 定义分块查找函数,参数为数组、数组长度、目标值和块大小。int block_count = (n + block_size - 1) / block_size
: 计算块的数量。for (int i = 0; i < block_count; i++)
: 遍历每个块。int start = i * block_size
: 计算当前块的起始索引。int end = start + block_size
: 计算当前块的结束索引。if (end > n) end = n
: 如果结束索引超过数组长度,调整结束索引。if (arr[end - 1] >= target)
: 如果目标值在当前块中。for (int j = start; j < end; j++)
: 在块中进行顺序查找。if (arr[j] == target)
: 如果找到目标值。return j
: 返回目标值的索引。return -1
: 如果未找到目标值,返回-1。
二叉排序树查找
查找算法原理:
二叉排序树(BST)是一种二叉树,每个节点的左子树所有值都小于该节点的值,右子树所有值都大于该节点的值。在BST中查找目标值时,通过比较当前节点值与目标值,决定在左子树或右子树中继续查找。
实现步骤:
- 从根节点开始。
- 比较当前节点值与目标值。
- 如果相等,返回该节点。
- 如果目标值小于当前节点值,在左子树中递归查找。
- 如果目标值大于当前节点值,在右子树中递归查找。
- 如果节点为空,返回未找到。
C语言代码:
#include <stdio.h>
#include <stdlib.h>struct TreeNode {int val;struct TreeNode *left, *right;
};struct TreeNode* create_node(int key) {struct TreeNode* new_node = (struct TreeNode*)malloc(sizeof(struct TreeNode));new_node->val = key;new_node->left = new_node->right = NULL;return new_node;
}struct TreeNode* insert(struct TreeNode* node, int key) {if (node == NULL) return create_node(key);if (key < node->val)node->left = insert(node->left, key);else if (key > node->val)node->right = insert(node->right, key);return node;
}struct TreeNode* search(struct TreeNode* root, int target) {if (root == NULL || root->val == target)return root;if (target < root->val)return search(root->left, target);return search(root->right, target);
}int main() {struct TreeNode* root = NULL;int keys[] = {20, 8, 22, 4, 12, 10, 14};int n = sizeof(keys) / sizeof(keys[0]);for (int i = 0; i < n; i++) {root = insert(root, keys[i]);}int target = 10;struct TreeNode* result = search(root, target);if (result != NULL) {printf("Element found: %d\n", result->val);} else {printf("Element not found\n");}return 0;
}
代码解释:
struct TreeNode
: 定义二叉排序树节点结构。struct TreeNode* create_node(int key)
: 创建新节点。struct TreeNode* insert(struct TreeNode* node, int key)
: 插入节点。struct TreeNode* search(struct TreeNode* root, int target)
: 查找节点。int main()
: 主函数,演示插入和查找操作。
平衡二叉树(AVL树)
查找算法原理:
平衡二叉树是一种自平衡的二叉排序树,其左右子树的高度差最多为1,确保查找、插入、删除的时间复杂度为O(log n)。
实现步骤:
- 插入节点后,通过旋转操作保持树的平衡。
- 左旋和右旋操作用于重新平衡树。
- 计算每个节点的高度以保持平衡。
C语言代码:
#include <stdio.h>
#include <stdlib.h>struct TreeNode {int val;struct TreeNode *left, *right;int height;
};int max(int a, int b) {return (a > b) ? a : b;
}int height(struct TreeNode *N) {return (N == NULL) ? 0 : N->height;
}struct TreeNode* create_node(int key) {struct TreeNode* node = (struct TreeNode*)malloc(sizeof(struct TreeNode));node->val = key;node->left = node->right = NULL;node->height = 1;return node;
}struct TreeNode* right_rotate(struct TreeNode *y) {struct TreeNode *x = y->left;struct TreeNode *T2 = x->right;x->right = y;y->left = T2;y->height = max(height(y->left), height(y->right)) + 1;x->height = max(height(x->left), height(x->right)) + 1;return x;
}struct TreeNode* left_rotate(struct TreeNode *x) {struct TreeNode *y = x->right;struct TreeNode *T2 = y->left;y->left = x;x->right = T2;x->height = max(height(x->left), height(x->right)) + 1;y->height = max(height(y->left), height(y->right)) + 1;return y;
}int get_balance(struct TreeNode *N) {return (N == NULL) ? 0 : height(N->left) - height(N->right);
}struct TreeNode* insert(struct TreeNode* node, int key) {if (node == NULL)return create_node(key);if (key < node->val)node->left = insert(node->left, key);else if (key > node->val)node->right = insert(node->right, key);elsereturn node;node->height = 1 + max(height(node->left), height(node->right));int balance = get_balance(node);if (balance > 1 && key < node->left->val)return right_rotate(node);if (balance < -1 && key > node->right->val)return left_rotate(node);if (balance > 1 && key > node->left->val) {node->left = left_rotate(node->left);return right_rotate(node);}if (balance < -1 && key < node->right->val) {node->right = right_rotate(node->right);return left_rotate(node);}return node;
}struct TreeNode* search(struct TreeNode* root, int target) {if (root == NULL || root->val == target)return root;if (target < root->val)return search(root->left, target);return search(root->right, target);
}int main() {struct TreeNode* root = NULL;int keys[] = {20, 8, 22, 4, 12, 10, 14};int n = sizeof(keys) / sizeof(keys[0]);for (int i = 0; i < n; i++) {root = insert(root, keys[i]);}int target = 10;struct TreeNode* result = search(root, target);if (result != NULL) {printf("Element found: %d\n", result->val);} else {printf("Element not found\n");}return 0;
}
代码解释:
- 定义AVL树节点结构,包含节点值、左子树、右子树和节点高度。
create_node
函数用于创建新节点。right_rotate
和left_rotate
函数用于保持树的平衡。get_balance
函数用于计算节点的平衡因子。insert
函数用于插入节点并保持树的平衡。search
函数用于查找节点。
红黑树
查找算法原理:
红黑树是一种自平衡的二叉查找树,每个节点包含一个颜色(红色或黑色)。通过节点颜色和旋转操作保持树的平衡,确保查找、插入、删除操作的时间复杂度为O(log n)。
实现步骤:
- 插入节点后通过颜色调整和旋转操作保持树的平衡。
- 左旋和右旋操作用于重新平衡树。
- 确保树的性质:根节点是黑色,红色节点的子节点是黑色,从任一节点到叶子节点的路径上黑色节点数相同。
C语言代码:
#include <stdio.h>
#include <stdlib.h>enum Color { RED, BLACK };struct TreeNode {int val;enum Color color;struct TreeNode *left, *right, *parent;
};struct TreeNode* create_node(int key) {struct TreeNode* node = (struct TreeNode*)malloc(sizeof(struct TreeNode));node->val = key;node->color = RED;node->left = node->right = node->parent = NULL;return node;
}void left_rotate(struct TreeNode** root, struct TreeNode* x) {struct TreeNode* y = x->right;x->right = y->left;if (y->left != NULL) y->left->parent = x;y->parent = x->parent;if (x->parent == NULL)*root = y;else if (x == x->parent->left)x->parent->left = y;elsex->parent->right = y;y->left = x;x->parent = y;
}void right_rotate(struct TreeNode** root, struct TreeNode* y) {struct TreeNode* x = y->left;y->left = x->right;if (x->right != NULL) x->right->parent = y;x->parent = y->parent;if (y->parent == NULL)*root = x;else if (y == y->parent->left)y->parent->left = x;elsey->parent->right = x;x->right = y;y->parent = x;
}void insert_fixup(struct TreeNode** root, struct TreeNode* z) {while (z->parent != NULL && z->parent->color == RED) {if (z->parent == z->parent->parent->left) {struct TreeNode* y = z->parent->parent->right;if (y != NULL && y->color == RED) {z->parent->color = BLACK;y->color = BLACK;z->parent->parent->color = RED;z = z->parent->parent;} else {if (z == z->parent->right) {z = z->parent;left_rotate(root, z);}z->parent->color = BLACK;z->parent->parent->color = RED;right_rotate(root, z->parent->parent);}} else {struct TreeNode* y = z->parent->parent->left;if (y != NULL && y->color == RED) {z->parent->color = BLACK;y->color = BLACK;z->parent->parent->color = RED;z = z->parent->parent;} else {if (z == z->parent->left) {z = z->parent;right_rotate(root, z);}z->parent->color = BLACK;z->parent->parent->color = RED;left_rotate(root, z->parent->parent);}}}(*root)->color = BLACK;
}void insert(struct TreeNode** root, int key) {struct TreeNode* z = create_node(key);struct TreeNode* y = NULL;struct TreeNode* x = *root;while (x != NULL) {y = x;if (z->val < x->val)x = x->left;elsex = x->right;}z->parent = y;if (y == NULL)*root = z;else if (z->val < y->val)y->left = z;elsey->right = z;insert_fixup(root, z);
}struct TreeNode* search(struct TreeNode* root, int target) {while (root != NULL && root->val != target) {if (target < root->val)root= root->left;elseroot = root->right;}return root;
}int main() {struct TreeNode* root = NULL;int keys[] = {20, 8, 22, 4, 12, 10, 14};int n = sizeof(keys) / sizeof(keys[0]);for (int i = 0; i < n; i++) {insert(&root, keys[i]);}int target = 10;struct TreeNode* result = search(root, target);if (result != NULL) {printf("Element found: %d\n", result->val);} else {printf("Element not found\n");}return 0;
}
代码解释:
- 定义红黑树节点结构,包含节点值、颜色、左子树、右子树和父节点。
create_node
函数用于创建新节点。left_rotate
和right_rotate
函数用于保持树的平衡。insert_fixup
函数用于插入节点后的颜色调整和旋转操作。insert
函数用于插入节点并保持树的平衡。search
函数用于查找节点。
B树
查找算法原理:
B树是一种自平衡的树数据结构,广泛应用于数据库和文件系统中。B树节点可以有多个子节点和关键字,确保查找、插入、删除操作的时间复杂度为O(log n)。
实现步骤:
- B树的每个节点可以包含多个关键字和子节点。
- 关键字和子节点根据值进行分布。
- 插入和删除操作需要保持树的平衡,通过节点分裂和合并操作实现。
C语言代码:
#include <stdio.h>
#include <stdlib.h>#define T 3struct BTreeNode {int *keys;int t;struct BTreeNode **C;int n;int leaf;
};struct BTreeNode* create_node(int t, int leaf) {struct BTreeNode* node = (struct BTreeNode*)malloc(sizeof(struct BTreeNode));node->t = t;node->leaf = leaf;node->keys = (int*)malloc((2*t-1) * sizeof(int));node->C = (struct BTreeNode**)malloc((2*t) * sizeof(struct BTreeNode*));node->n = 0;return node;
}void traverse(struct BTreeNode* root) {int i;for (i = 0; i < root->n; i++) {if (!root->leaf)traverse(root->C[i]);printf(" %d", root->keys[i]);}if (!root->leaf)traverse(root->C[i]);
}struct BTreeNode* search(struct BTreeNode* root, int k) {int i = 0;while (i < root->n && k > root->keys[i])i++;if (root->keys[i] == k)return root;if (root->leaf)return NULL;return search(root->C[i], k);
}void insert_non_full(struct BTreeNode* x, int k);
void split_child(struct BTreeNode* x, int i, struct BTreeNode* y);void insert(struct BTreeNode** root, int k) {struct BTreeNode* r = *root;if (r->n == 2*T-1) {struct BTreeNode* s = create_node(r->t, 0);s->C[0] = r;split_child(s, 0, r);int i = 0;if (s->keys[0] < k)i++;insert_non_full(s->C[i], k);*root = s;} else {insert_non_full(r, k);}
}void split_child(struct BTreeNode* x, int i, struct BTreeNode* y) {struct BTreeNode* z = create_node(y->t, y->leaf);z->n = T - 1;for (int j = 0; j < T-1; j++)z->keys[j] = y->keys[j+T];if (!y->leaf) {for (int j = 0; j < T; j++)z->C[j] = y->C[j+T];}y->n = T - 1;for (int j = x->n; j >= i+1; j--)x->C[j+1] = x->C[j];x->C[i+1] = z;for (int j = x->n-1; j >= i; j--)x->keys[j+1] = x->keys[j];x->keys[i] = y->keys[T-1];x->n = x->n + 1;
}void insert_non_full(struct BTreeNode* x, int k) {int i = x->n - 1;if (x->leaf) {while (i >= 0 && x->keys[i] > k) {x->keys[i+1] = x->keys[i];i--;}x->keys[i+1] = k;x->n = x->n + 1;} else {while (i >= 0 && x->keys[i] > k)i--;if (x->C[i+1]->n == 2*T-1) {split_child(x, i+1, x->C[i+1]);if (x->keys[i+1] < k)i++;}insert_non_full(x->C[i+1], k);}
}int main() {struct BTreeNode* root = create_node(T, 1);int keys[] = {10, 20, 5, 6, 12, 30, 7, 17};int n = sizeof(keys) / sizeof(keys[0]);for (int i = 0; i < n; i++) {insert(&root, keys[i]);}printf("Traversal of the constructed tree is ");traverse(root);int target = 6;struct BTreeNode* result = search(root, target);if (result != NULL) {printf("\nElement found");} else {printf("\nElement not found");}return 0;
}
代码解释:
- 定义B树节点结构,包含关键字、子节点、关键字数量和是否为叶子节点。
create_node
函数用于创建新节点。traverse
函数用于遍历B树。search
函数用于查找节点。insert
函数用于插入节点。split_child
函数用于分裂节点。insert_non_full
函数用于在非满节点中插入关键字。
B+树
查找算法原理:
B+树是B树的一种变种,所有数据都存储在叶子节点中,并且叶子节点通过链表相连。B+树的非叶子节点只存储索引,便于范围查找。
实现步骤:
- B+树的每个节点可以包含多个关键字和子节点。
- 关键字和子节点根据值进行分布。
- 插入和删除操作需要保持树的平衡,通过节点分裂和合并操作实现。
C语言代码:
#include <stdio.h>
#include <stdlib.h>#define T 3struct BPlusTreeNode {int *keys;struct BPlusTreeNode **C;struct BPlusTreeNode *next;int n;int leaf;
};struct BPlusTreeNode* create_node(int leaf) {struct BPlusTreeNode* node = (struct BPlusTreeNode*)malloc(sizeof(struct BPlusTreeNode));node->keys = (int*)malloc((2*T-1) * sizeof(int));node->C = (struct BPlusTreeNode**)malloc((2*T) * sizeof(struct BPlusTreeNode*));node->next = NULL;node->n = 0;node->leaf = leaf;return node;
}void traverse(struct BPlusTreeNode* root) {struct BPlusTreeNode* current = root;while (!current->leaf)current = current->C[0];while (current) {for (int i = 0; i < current->n; i++)printf(" %d", current->keys[i]);current = current->next;}
}struct BPlusTreeNode* search(struct BPlusTreeNode* root, int k) {int i = 0;while (i < root->n && k > root->keys[i])i++;if (i < root->n && root->keys[i] == k)return root;if (root->leaf)return NULL;return search(root->C[i], k);
}void insert_non_full(struct BPlusTreeNode* x, int k);
void split_child(struct BPlusTreeNode* x, int i, struct BPlusTreeNode* y);void insert(struct BPlusTreeNode** root, int k) {struct BPlusTreeNode* r = *root;if (r->n == 2*T-1) {struct BPlusTreeNode* s = create_node(0);s->C[0] = r;split_child(s, 0, r);int i = 0;if (s->keys[0] < k)i++;insert_non_full(s->C[i], k);*root = s;} else {insert_non_full(r, k);}
}void split_child(struct BPlusTreeNode* x, int i, struct BPlusTreeNode* y) {struct BPlusTreeNode* z = create_node(y->leaf);z->n = T - 1;for (int j = 0; j < T-1; j++)z->keys[j] = y->keys[j+T];if (!y->leaf) {for (int j = 0; j < T; j++)z->C[j] = y->C[j+T];} else {z->next = y->next;y->next = z;}y->n = T - 1;for (int j = x->n; j >= i+1; j--)x->C[j+1] = x->C[j];x->C[i+1] = z;for (int j = x->n-1; j >= i; j--)x->keys[j+1] = x->keys[j];x->keys[i] = y->keys[T-1];x->n = x->n + 1;
}void insert_non_full(struct BPlusTreeNode* x, int k) {int i = x->n - 1;if (x->leaf) {while (i >= 0 && x->keys[i] > k) {x->keys[i+1] = x->keys[i];i--;}x->keys[i+1] = k;x->n = x->n + 1;} else {while (i >= 0 && x->keys[i] > k)i--;if (x->C[i+1]->n == 2*T-1) {split_child(x, i+1, x->C[i+1]);if (x->keys[i+1] < k)i++;}insert_non_full(x->C[i+1], k);}
}int main() {struct BPlusTreeNode* root = create_node(1);int keys[] = {10, 20, 5, 6, 12, 30, 7, 17};int n = sizeof(keys) / sizeof(keys[0]);for (int i = 0; i < n; i++) {insert(&root, keys[i]);}printf("Traversal of the constructed B+ tree is ");traverse(root);int target = 6;struct BPlusTreeNode* result = search(root, target);if (result != NULL) {printf("\nElement found");} else {printf("\nElement not found");}return 0;
}
代码解释:
- 定义B+树节点结构,包含关键字、子节点、下一个节点、关键字数量和是否为叶子节点。
create_node
函数用于创建新节点。traverse
函数用于遍历B+树。search
函数用于查找节点。insert
函数用于插入节点。split_child
函数用于分裂节点。insert_non_full
函数用于在非满节点中插入关键字。
散列查找
查找算法原理:
散列查找通过散列函数将关键字映射到数组中的位置。使用链地址法处理散列冲突,每个数组位置存储一个链表,链表中的每个节点包含具有相同散列值的关键字。
实现步骤:
- 使用散列函数计算关键字的散列值。
- 根据散列值将关键字插入对应位置的链表中。
- 查找时,计算关键字的散列值,然后在链表中查找目标值。
C语言代码:
#include <stdio.h>
#include <stdlib.h>#define TABLE_SIZE 10struct Node {int key;struct Node* next;
};struct Node* hash_table[TABLE_SIZE];unsigned int hash(int key) {return key % TABLE_SIZE;
}void insert(int key) {unsigned int index = hash(key);struct Node* new_node = (struct Node*)malloc(sizeof(struct Node));new_node->key = key;new_node->next = hash_table[index];hash_table[index] = new_node;
}struct Node* search(int key) {unsigned int index = hash(key);struct Node* current = hash_table[index];while (current != NULL) {if (current->key == key)return current;current = current->next;}return NULL;
}void display() {for (int i = 0; i < TABLE_SIZE; i++) {struct Node* current = hash_table[i];printf("hash_table[%d]: ", i);while (current != NULL) {printf("%d -> ", current->key);current = current->next;}printf("NULL\n");}
}int main() {insert(10);insert(20);insert(15);insert(7);insert(32);display();int target = 15;struct Node* result = search(target);if (result != NULL) {printf("Element found: %d\n", result->key);} else {printf("Element not found\n");}return 0;
}
代码解释:
- 定义链表节点结构,包含关键字和下一个节点指针。
- 定义哈希表为链表节点指针数组。
hash
函数用于计算关键字的散列值。insert
函数用于插入关键字到哈希表。search
函数用于查找关键字。display
函数用于显示哈希表的内容。
相关文章:
算法 - 查找算法(顺序、折半、红黑树、AVL树、B+树、散列)
查找 顺序查找 查找算法原理: 顺序查找是一种简单的查找方法,从数组的第一个元素开始,依次比较每个元素,直到找到目标元素或者数组结束为止。 实现步骤: 从数组的第一个元素开始。逐一比较数组中的元素与目标值。如…...

TCP与UDP网络编程
网络通信协议 java.net 包中提供了两种常见的网络协议的支持: UDP:用户数据报协议(User Datagram Protocol)TCP:传输控制协议(Transmission Control Protocol) TCP协议与UDP协议 TCP协议 TCP协议进行通信的两个应用进程:客户端、服务端 …...

媲美Midjourney-v6,Kolors最新文生图模型部署
Kolors模型是由快手团队开发的大型文本到图像生成模型,专门用于将文本描述转换成高质量的图像。 Kolors模型支持中英文双语输入,生成效果与Midjourney-v6相媲美,能够处理长达256个字符的文本输入,具备生成中英文文字的能力。 Ko…...

深度学习程序环境配置
深度学习环境配置 因为之前轻薄本没有显卡跑不起来,所以换了台电脑重新跑程序,故记录一下配置环境的步骤及常见错误 本人数学系,计算机部分知识比较匮乏,计算机专业同学可以略过部分内容 深度学习环境配置 深度学习环境配置 CUD…...

【STM32 HAL库】全双工I2S+双缓冲DMA的使用
1、配置I2S 我们的有效数据是32位的,使用飞利浦格式。 2、配置DMA **这里需要注意:**i2s的DR寄存器是16位的,如果需要发送32位的数据,是需要写两次DR寄存器的,所以DMA的外设数据宽度设置16位,而不是32位。…...

【Spring Boot】网页五子棋项目中遇到的困难及解决方法
目录 一、HikariPool-1 - Starting异常二、Invalid bound statement (not found)异常三、The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary异常四、The server time zone value时区报错异常五、补充知识点…...
营销策划方案模板
这应该是目前最详细最完整的营销策划方案模板,营销公司内部都在使用的标准版本,你可以根据自己的营销内容直接填入这个模板,很快就能写好一份至少80分的营销策划方案。 如果暂时用不到也可以先收藏,以备不时之需。 废话不多说&a…...

Python入门基础教程(非常详细)
现在找工作真的越来越难了!今年更是难上加难 前几天在网上刷到这样一条热搜: #23岁找工作因年龄大被HR拒绝了# 是这个世界疯了还是我疯了? 合着只想要有20年以上工作经验的应届毕业生是吧 这好像就是现在的就业市场现状:“35岁…...
LeetCode 常见题型汇总
前30 22 生成括号 剪枝 51 N皇后 37 解数独 二分查找 69 求平方根 字典树 位运算 191 求1的个数 231 2的N次方 338 求0到N的比特位为1的个数 动态规划 并查集 LRU缓存 布隆过滤器...

el-select选择器修改背景颜色
<!--* FilePath: topSearch.vue* Author: 是十九呐* Date: 2024-07-18 09:46:03* LastEditTime: 2024-07-18 10:42:03 --> <template><div class"topSearch-container"><div class"search-item"><div class"item-name&quo…...

Shell程序设计
各位看官,从今天开始,我们进入新的专栏Shell学习,Shell 是操作系统的命令行界面,它允许用户通过输入命令与操作系统交互。常见的 Shell 有 Bash 和 Zsh,它们可以执行用户输入的命令或运行脚本文件。Shell 广泛应用于系…...

PyQT6---环境搭建
1、虚拟环境搭建 创建虚拟环境 create -n pyqt6_39 python3.9 切换虚拟环境 conda activate pyqt6_39 2、安装pyqt6 安装pyqt6和pyqt6-tools pip install PyQt6 -i https://pypi.tuna.tsinghua.edu.cn/simplepip install pyqt6-tools -i https://pypi.tuna.tsinghua.edu.cn/…...
whisper-api语音识别语音翻译高性能兼容openai接口协议的开源项目
whisper-api 介绍 使用openai的开源项目winsper语音识别开源模型封装成openai chatgpt兼容接口 软件架构 使用uvicorn、fastapi、openai-whisper等开源库实现高性能接口 更多介绍 https://blog.csdn.net/weixin_40986713/article/details/138712293 使用说明 下载代码安装…...
面试题:Java中堆内存和栈内存的区别,缓存数据是把数据放到哪里
目录 堆内存(Heap)栈内存(Stack)String字符串的hashcode缓存 在Java中,堆内存(Heap)和栈内存(Stack)是两种不同类型的内存区域。它们各自扮演着不同的角色,并…...
【开源库学习】libodb库学习(一)
Hello World Example 在本章中,我们将使用传统的“Hello World”示例展示如何创建一个依赖于ODB进行对象持久化的简单C应用程序。特别是,我们将讨论如何声明持久类、生成数据库支持代码以及编译和运行我们的应用程序。我们还将学习如何使对象持久化&…...

Java中SPI机制原理解析
使用SPI机制前后的代码变化 加载MySQL对JDBC的Driver接口实现 在未使用SPI机制之前,使用JDBC操作数据库的时候,一般会写如下的代码:// 通过这行代码手动加载MySql对Driver接口的实现类 Class.forName("com.mysql.jdbc.Driver") Dr…...

数学建模~~~SPSS相关和回归分析
目录 1.双变量相关分析 1.1理论基础 1.2简单散点图的绘制介绍 1.3相关性分析 1.4分析相关性结果 2.简单线性回归分析 2.1简单概括 2.2分析过程 2.3结果分析 3.曲线回归分析 3.1问题介绍 3.2分析过程 3.3结果分析 1.双变量相关分析 1.1理论基础 双变量相关分析并不…...

【Android】常用基础布局
布局是一种可用于放置很多控件的容器,它可以按照一定的规律调整内部控件的位置,从而编写出精美的界面,布局内不单单可以放控件,也可以嵌套布局,这样可以完成一些复杂的界面,下面就来认识一些常用的布局吧。…...

服务攻防-中间件安全(漏洞复现)
一.中间件-IIS-短文件&解析&蓝屏 IIS现在用的也少了,漏洞也基本没啥用 1、短文件:信息收集 2、文件解析:还有点用 3、HTTP.SYS:蓝屏崩溃 没有和权限挂钩 4、CVE-2017-7269 条件过老 windows 2003上面的漏洞 二.中…...

【SD】深入理解Stable Diffusion与ComfyUI的使用
【SD】深入理解Stable Diffusion与ComfyUI的使用 1. Stable Diffusion(SD)原理概述2. 各部件详解3. SD的工作流程4. ComfyUI与SD的结合5. 总结 1. Stable Diffusion(SD)原理概述 整体结构:SD不是单一模型,…...

微信小程序之bind和catch
这两个呢,都是绑定事件用的,具体使用有些小区别。 官方文档: 事件冒泡处理不同 bind:绑定的事件会向上冒泡,即触发当前组件的事件后,还会继续触发父组件的相同事件。例如,有一个子视图绑定了b…...

第一篇:Agent2Agent (A2A) 协议——协作式人工智能的黎明
AI 领域的快速发展正在催生一个新时代,智能代理(agents)不再是孤立的个体,而是能够像一个数字团队一样协作。然而,当前 AI 生态系统的碎片化阻碍了这一愿景的实现,导致了“AI 巴别塔问题”——不同代理之间…...

AI书签管理工具开发全记录(十九):嵌入资源处理
1.前言 📝 在上一篇文章中,我们完成了书签的导入导出功能。本篇文章我们研究如何处理嵌入资源,方便后续将资源打包到一个可执行文件中。 2.embed介绍 🎯 Go 1.16 引入了革命性的 embed 包,彻底改变了静态资源管理的…...
Mobile ALOHA全身模仿学习
一、题目 Mobile ALOHA:通过低成本全身远程操作学习双手移动操作 传统模仿学习(Imitation Learning)缺点:聚焦与桌面操作,缺乏通用任务所需的移动性和灵活性 本论文优点:(1)在ALOHA…...
MySQL 8.0 事务全面讲解
以下是一个结合两次回答的 MySQL 8.0 事务全面讲解,涵盖了事务的核心概念、操作示例、失败回滚、隔离级别、事务性 DDL 和 XA 事务等内容,并修正了查看隔离级别的命令。 MySQL 8.0 事务全面讲解 一、事务的核心概念(ACID) 事务是…...

HubSpot推出与ChatGPT的深度集成引发兴奋与担忧
上周三,HubSpot宣布已构建与ChatGPT的深度集成,这一消息在HubSpot用户和营销技术观察者中引发了极大的兴奋,但同时也存在一些关于数据安全的担忧。 许多网络声音声称,这对SaaS应用程序和人工智能而言是一场范式转变。 但向任何技…...

CVPR2025重磅突破:AnomalyAny框架实现单样本生成逼真异常数据,破解视觉检测瓶颈!
本文介绍了一种名为AnomalyAny的创新框架,该方法利用Stable Diffusion的强大生成能力,仅需单个正常样本和文本描述,即可生成逼真且多样化的异常样本,有效解决了视觉异常检测中异常样本稀缺的难题,为工业质检、医疗影像…...
c# 局部函数 定义、功能与示例
C# 局部函数:定义、功能与示例 1. 定义与功能 局部函数(Local Function)是嵌套在另一个方法内部的私有方法,仅在包含它的方法内可见。 • 作用:封装仅用于当前方法的逻辑,避免污染类作用域,提升…...

【Linux】Linux安装并配置RabbitMQ
目录 1. 安装 Erlang 2. 安装 RabbitMQ 2.1.添加 RabbitMQ 仓库 2.2.安装 RabbitMQ 3.配置 3.1.启动和管理服务 4. 访问管理界面 5.安装问题 6.修改密码 7.修改端口 7.1.找到文件 7.2.修改文件 1. 安装 Erlang 由于 RabbitMQ 是用 Erlang 编写的,需要先安…...
前端调试HTTP状态码
1xx(信息类状态码) 这类状态码表示临时响应,需要客户端继续处理请求。 100 Continue 服务器已收到请求的初始部分,客户端应继续发送剩余部分。 2xx(成功类状态码) 表示请求已成功被服务器接收、理解并处…...