数据结构--线性表

注:把我大二的数据结构实验报告当中书写的代码做一个记录,此系列仅为代码分享,无解析

1.实现顺序表的各种基本运算:

#include<stdio.h>
#include<stdlib.h>
typedef struct
{int* data;int length;int capacity;
}SqList;
//创建顺序表 
void createList(int capacity, SqList **list) {*list = (SqList*)malloc(sizeof(SqList));if (*list == NULL) {printf("Failed to allocate memory for the sequence list.\n");return ;}(*list)->data = (int*)malloc(capacity * sizeof(int));if ((*list)->data == NULL) {printf("Failed to allocate memory for the data array.\n");free(*list);*list = NULL;return ;}(*list)->length = 0;(*list)->capacity = capacity;
}
//初始化顺序表
void initSqList(SqList* list)
{if(list != NULL)list->length = 0;
}
//销毁线性表 
void destroyList(SqList* list)
{if(list != NULL){free(list->data);free(list);}
}
//判断线性表是否为空
//这里的话使用bool类型的函数也可以  如:bool ListEmpty(SqList* list) 
int  ListEmpty(SqList* list)
{return list->length == 0;
}
//求线性表长度
int Listlength(SqList* list) 
{return list->length;
} 
//输出线性表
void dispList(SqList* list)
{int i = 0;for(i = 0;i < list->length;i++)printf("%d ",list->data[i]);printf("\n");
} 
//求出线性表当中的第n个元素
int getelem(SqList* list,int n)
{if(n < 1 || n > list->length){printf("Invalid index\n");return -1;  }return list->data[n - 1];
}
//查找第一个值为n的元素位置
int locateElem(SqList* list,int n)
{int i = 0;if( i < list->length && list->data[i] != n)i++;if( i > list->length){printf("Invalid element");return 0;}elsereturn i+1;  
}
//插入第i个元素 
int listinsert(SqList* list,int i,int n)
{if( i < 1 || i > list->length + 1 || list->length >= list->capacity){ printf("Invalid position\n");return -1;}/*if(list->length == list->capacity){printf("SqList is full\n");return -1;}*/int j = 0;for (j = list->length; j >= i;j--){list->data[j] = list->data[j - 1];}list->data[i-1] = n;list->length++;
}
//删除第i个元素
int deletelist(SqList *list,int i)
{if(i < 1 || i > list->length || list->length >= list->capacity){printf("Invalid position");return -1;}int j;for (j = i - 1;j < list->length - 1; j++){list->data[j] = list->data[j+1];}list->data[list->length - 1] = 0;list->length--;
} 
int main()
{SqList* list;createList(10,&list);if (list != NULL){initSqList(list);if(ListEmpty(list)){printf ("The sequence list is empty.\n");}else{printf ("The sequence list is not empty.\n");}int length = Listlength(list);printf("The length of the sequence list is :%d\n",length);list->data[0] = 7;list->data[1] = 4;list->data[2] = 3;list->length = 3;dispList(list);int elem = getelem(list,2);printf("The value of the n element is %d\n",elem);int locate = locateElem(list, 4);printf("The position of the first element with a value of n is %d\n",locate);listinsert(list,1,8);printf("The sequence list after adding the element is:\n");dispList(list);deletelist(list,2);printf("The sequence list after deleteing the element is:\n");dispList(list);destroyList(list);}return 0;
}

2.实现单链表的各种基本运算:

#include<stdio.h>
#include<stdlib.h>
//创建节点 
typedef char ElemType; 
typedef struct Node{ElemType data;struct Node* next;
}Node;
//头插法创建一个单链表
Node* createlistf(int data[],int n)
{Node* head = NULL;int i = 0;for(i = 0; i < n; i++){Node* newNode = (Node*)malloc(sizeof(Node));if (newNode == NULL){printf("位置不合法");return NULL;}newNode->data = data[i];newNode->next = head;head = newNode;}return head;
} 
// 尾插法建立单链表
Node* createlistR(int data[],int n)
{Node *head = NULL;;Node *tail = NULL;;int i = 0;for (i = 0; i < n; i++){Node* newNode = (Node*)malloc(sizeof(Node));if (newNode == NULL){printf("位置不合法");return NULL;}newNode->data = data[i];newNode->next = NULL;if (head == NULL){head = newNode;tail = newNode;}else{tail->next = newNode;tail = newNode;}} return head;
} 
//初始化线性表
void initlist(Node **head)
{*head = (Node*)malloc(sizeof(Node));(*head)->next = NULL;
} 
//销毁线性表
void destroylist(Node **head)
{Node *current = *head;Node *next = NULL;while (current != NULL){next = current->next;free(current);current = next;}*head = NULL;
}
//判断线性表是否为空
void emptylist(Node *head)
{if (head == NULL)printf("链表是空的\n");elseprintf("链表为非空\n"); 
} 
//求线性表的长度
int lengthlist(Node *head)
{int i = 0;Node *p =head;while (p != NULL){i++;p = p->next;}return i;
} 
//打印线性表 
void printflist(Node *head)
{Node *p = head;while (p != NULL){printf("%d ", p->data);p = p->next;}printf("\n");
}
//求线性表中第i个元素
int getelem(Node *head,int i)
{Node *p = head;if (i < 1 || p == NULL){printf("无效位置\n");return -1;  }int j = 0;for( j = 1; j < i; j++){if (p->next == NULL){printf("索引越界\n");return -1;}p = p->next;}return p->data;
}
//求值为i的元素序号
int locatelist(Node *head,int i)
{int n = 1;Node *p = head;while ( p != NULL && p->data != i){p = p->next;n++;}if (p == NULL){printf ("%d不存在\n",i);return 0;}else{printf ("值为%d的位置为%d\n",i,n);return 0;}
}
//插入第i个元素
int insertlist(Node **head, int i, int n)
{Node *p = *head;Node *s = (Node*)malloc(sizeof(Node));s->data = n;if (p == NULL && i != 1){printf("线性表是空的\n");return -1;}if (i == 1){s->next = p;*head = s;return 0;}int j = 1;while (p != NULL && j < i - 1){p = p->next;j++;}if (p == NULL){printf("索引越界\n");return -1;}else{s->next = p->next;p->next = s;return 0;}
}
/*int insertlist(Node **head, int i, int n)
{if (*head == NULL){// 创建新的头节点*head = (Node*)malloc(sizeof(Node));(*head)->data = n;(*head)->next = NULL;return 0;}Node *p = *head;Node *prev = NULL;int j = 0;for (j = 0; j < i - 1; j++){if (p == NULL){printf("Index out of bounds\n");return -1;}prev = p;p = p->next;}if (p == NULL){printf("Index out of bounds\n");return -1;}Node *s = (Node*)malloc(sizeof(Node));s->data = n;s->next = p;if (prev == NULL){// 在头部插入元素*head = s;}else{prev->next = s;}return 0;
}
*/
//删除第i个元素
int deletelist(Node **head, int i)
{Node *p = *head;Node *q = NULL;// 删除头节点if (i == 1) {*head = p->next;free(p);return 0;}int j = 1;// 找到第i-1个节点while (p != NULL && j < i ){p = p->next;j++;}// 如果第i-1个节点不存在或者第i个节点不存在,返回错误if (p == NULL || p->next == NULL){printf("索引越界\n");return -1;}else{q = p->next;p->next = q->next;free(q);return 0;}
}
int main()
{int data1[] = {1 , 3 , 5 , 7 , 9};int n1 = sizeof(data1) / sizeof(data1[0]);int data2[] = {2 , 4 , 6 , 8 , 10};int n2 = sizeof(data2) / sizeof(data2[0]);// 使用头插法创建链表Node* head1 = createlistf(data1, n1);// 使用尾插法创建链表Node* head2 = createlistR(data2, n2);//测试用例 //printflist(head1);//printflist(head2); //初始化线性表 Node *head = NULL;initlist(&head);head = head1;//判断线性表是否为空emptylist(head); //求线性表长度int length = lengthlist(head);printf ("表的长度是 %d\n",length); //打印线性表printf("表为:");printflist(head);//线性表中第i个元素的值int elem = getelem(head,3);printf("第3个位置的值是%d\n",elem);//求第一个值为i的元素序号locatelist(head,9); //插入第i个元素insertlist(&head,3,6);printflist(head);//删除第i个元素deletelist(&head,2);printflist(head);//删除线性表 destroylist(&head);return 0;
}

3.实现双向链表的各种基本运算:

#include<stdio.h>
#include<stdlib.h>
typedef char ElemType;
typedef struct DNode
{ElemType data;struct DNode* prior;struct DNode* next;
}DLinkNode;
//头插法
DLinkNode* createListF(int data[],int n) {DLinkNode* head = NULL;int i = 0;for (i = 0; i < n; i++){DLinkNode* newNode = (DLinkNode*)malloc(sizeof(DLinkNode));if (newNode == NULL) {printf("内存分配失败\n");return NULL;}newNode->data = data[i];newNode->prior = NULL;newNode->next = head;if (head != NULL) {head->prior = newNode;}head = newNode;}return head; 
}
//尾插法
DLinkNode* createListR(int data[], int n)
{DLinkNode* head = NULL;DLinkNode* tail = NULL;int i;for (i = 0; i < n; i++){DLinkNode* newNode = (DLinkNode*)malloc(sizeof(DLinkNode));if (newNode == NULL){printf("内存分配失败\n");return NULL;}newNode->data = data[i];newNode->next = NULL;if (head == NULL){newNode->prior = NULL;head = newNode;tail = newNode;}else{tail->next = newNode;newNode->prior = tail;tail = newNode;}}return head;
}
//打印链表 
void printflist(DLinkNode *head)
{DLinkNode *p = head;while (p != NULL){printf("%d ", p->data);p = p->next;}printf("\n");
}
//初始化双向链表
void initlist(DLinkNode** head)
{*head = (DLinkNode*)malloc(sizeof(DLinkNode));(*head)->prior = NULL;(*head)->next = NULL;
}
//销毁双向链表
void destroylist(DLinkNode** head)
{DLinkNode* current = *head;DLinkNode* next = NULL;while (current != NULL){next = current->next;free(current);current = next;}*head = NULL;
}
//判断双向链表是否为空
void emptylist(DLinkNode* head)
{if (head == NULL)printf("链表是空的\n");elseprintf("链表为非空\n");
}
//求线性表长度
int lengthlist(DLinkNode* head)
{int i = 0;DLinkNode* p = head;while (p != NULL){i++;p = p->next;}return i;
}
//求第i个元素的值
int getelem(DLinkNode* head, int i)
{DLinkNode* p = head;if (i < 1 || p == NULL){printf("无效位置");return -1;}int j = 0;for (j = 1; j < i; j++){if (p->next == NULL){printf("索引越界");return -1;}p = p->next;}return p->data;
}
//求值为i的元素序号
int locatelist(DLinkNode *head,int i)
{int n = 1;DLinkNode *p = head;while ( p != NULL && p->data != i){p = p->next;n++;}if (p == NULL){printf ("%d不存在\n",i);return 0;}else{printf ("值为%d的位置为%d\n",i,n);return 0;}
}
//插入第i个元素
int insertlist(DLinkNode** head, int i, int n)
{DLinkNode* p = *head;DLinkNode* s = (DLinkNode*)malloc(sizeof(DLinkNode));s->data = n;if (p == NULL && i != 1){printf("线性表是空的\n");return -1;}if (i == 1){s->next = p;*head = s;return 0;}int j = 1;while (p != NULL && j < i - 1){p = p->next;j++;}if (p == NULL){printf("索引越界\n");return -1;}else{s->prior = p;s->next = p->next;if (p->next != NULL) {p->next->prior = s;  // 这里需要先判断 p->next 是否为空}p->next = s;return 0;}
}
//删除第i个元素
int deletelist(DLinkNode** head, int i)
{if (*head == NULL || i < 1) {printf("链表为空或索引无效\n");return -1;}DLinkNode* p = *head;int j = 1;// 移动到第i个节点while (p != NULL && j < i) {p = p->next;j++;}// 如果第i个节点不存在if (p == NULL) {printf("第%d个节点不存在\n", i);return -1;}// 如果是头节点if (p == *head) {*head = p->next; // 更新头节点if (*head != NULL) {(*head)->prior = NULL; // 更新新的头节点的前驱指针}} else {p->prior->next = p->next; // 更新前一个节点的next指针if (p->next != NULL) {p->next->prior = p->prior; // 更新后一个节点的prior指针}}free(p); // 释放当前节点return 0;
}
int main(){int data1[] = {1 , 3 , 5 , 7 , 9};int n1 = sizeof(data1) / sizeof(data1[0]);int data2[] = {2 , 4 , 6 , 8 , 10};int n2 = sizeof(data2) / sizeof(data2[0]);// 使用头插法创建链表DLinkNode* head1 = createListF(data1, n1);// 使用尾插法创建链表DLinkNode* head2 = createListR(data2, n2);//测试用例 //printflist(head1);//printflist(head2);//初始化线性表 DLinkNode *head = NULL;initlist(&head);head = head1;//判断线性表是否为空emptylist(head); //求线性表长度int length = lengthlist(head);printf ("表的长度是 %d\n",length); //打印线性表printf("表为:");printflist(head);//线性表中第i个元素的值int elem = getelem(head,3);printf("第3个位置的值是%d\n",elem);//求第一个值为i的元素序号locatelist(head,9); //插入第i个元素insertlist(&head,3,6);printflist(head);//删除第i个元素deletelist(&head,2);printflist(head);//删除线性表 destroylist(&head);return 0;
}

4.实现单向循环链表的各种基本运算:

#include<stdio.h>
#include<stdlib.h>
typedef int ElemType;
typedef struct Node {ElemType data;struct LinkNode* next;
}LinkNode;
//头插法
LinkNode* createlistF(int data[], int n)
{LinkNode* head = NULL;LinkNode* tail = NULL;int i = 0;for (i = 0; i < n; i++){LinkNode* newNode = (LinkNode*)malloc(sizeof(LinkNode));if (newNode == NULL){printf("内存分配失败\n");return NULL;}newNode->data = data[i];if (head == NULL){head = newNode;tail = newNode;newNode->next = head;}else{newNode->next = head;head = newNode;tail->next = head;}}return head;
}
//尾插法
LinkNode* createlistR(int data[], int n)
{LinkNode* head = NULL;LinkNode* tail = NULL;int i = 0;for (i = 0; i < n; i++){LinkNode* newNode = (LinkNode*)malloc(sizeof(LinkNode));if (newNode == NULL){printf("内存分配失败\n");return NULL;}newNode->data = data[i];if (head == NULL){head = newNode;tail = newNode;newNode->next = head;}else{tail->next = newNode;tail = newNode;tail->next = head;}}return head;
}
//打印循环单链表 
void printflist(LinkNode *head)
{LinkNode *p = head;do {printf("%d ", p->data);p = p->next;} while (p != head);printf("\n");
}
//初始化
void initlist(LinkNode** head)
{*head = (LinkNode*)malloc(sizeof(LinkNode));(*head)->next = *head;
}
//销毁
void destroylist(LinkNode** head)
{LinkNode* current = *head;LinkNode* next = NULL;while (current != NULL){next = current->next;free(current);current = next;}*head = NULL;
}
//判断是否为空
void emptylist(LinkNode* head)
{if (head == NULL){printf("线性表为空\n");}else{printf("线性表为非空\n");}
}
//求线性表长度 
int lengthlist(LinkNode* head)
{int i = 0;LinkNode* p = head;do{i++;p = p->next;}while(p != head);return i;
}
//得到第i个元素
int getelem(LinkNode* head, int i)
{LinkNode* p = head;if (i < 1 || p == NULL){printf("无效位置\n");return -1;}int j = 0;for (j = 1; j < i; j++){if (p->next == NULL){printf("索引越界\n");return -1;}p = p->next;}return p->data;
}
//求值为i的元素序号
/*int locatelist(LinkNode* head, int i)
{int n = 1;int length = lengthlist(head);LinkNode* p = head;while (p != NULL && p->data != i){p = p->next;n++;if (n > length){break;}} if (p == NULL && n > length){printf("%d不存在\n", i);return 0;}else{printf("%d的位置是%d\n", i, n);return 0;}
}*/
int locatelist(LinkNode* head, int i) {if (head == NULL) {printf("链表为空\n");return -1;}int n = 1;LinkNode* p = head;do {if (p->data == i) {printf("%d的位置是%d\n", i, n);return n;}p = p->next;n++;} while (p != head); // 循环直到回到头节点// 如果没有找到printf("%d不存在\n", i);return -1;
}
//插入第i个元素
/*int insertlist(LinkNode** head, int i, int n)
{LinkNode* current = *head;LinkNode* newNode = (LinkNode*)malloc(sizeof(LinkNode));newNode->data = n;if (current == NULL && i != 1){printf("线性表是空的");return - 1;}if (i == 1){newNode->next = current;*head = newNode;return 0;}int j = 1;do{current = current->next;j++;} while (current != *head && j < i - 1);if (current == head){printf("索引越界");return -1;}else{newNode->next = current->next;current->next = newNode;return 0;}
}*/
int insertlist(LinkNode** head, int i, int n) {if (i < 1) {printf("插入位置不合法\n");return -1;}LinkNode* newNode = (LinkNode*)malloc(sizeof(LinkNode));if (!newNode) {printf("内存分配失败\n");return -1;}newNode->data = n;// 插入到链表为空或者插入到第一个位置时if (*head == NULL || i == 1) {newNode->next = newNode; // 新节点指向自己,形成循环if (*head != NULL) {// 找到链表的最后一个节点LinkNode* last = *head;while (last->next != *head) {last = last->next;}last->next = newNode; // 更新最后一个节点的next指针}*head = newNode; // 更新头指针return 0;}// 插入到链表中间或尾部的情况LinkNode* current = *head;int j = 1;while (current->next != *head && j < i - 1) {current = current->next;j++;}// 如果位置超过链表长度if (j != i - 1) {printf("索引越界\n");free(newNode); // 释放新节点的内存return -1;}newNode->next = current->next;current->next = newNode;return 0;
}
//删除第i个元素
int deletelist(LinkNode** head, int i) {if (*head == NULL || i < 1) {printf("链表为空或者位置不正确\n");return -1;}LinkNode* current = *head;LinkNode* toDelete = NULL;if (i == 1) {toDelete = *head;// 如果链表中只有一个节点if ((*head)->next == *head) {*head = NULL;} else {// 将头节点的前一个节点的next指向头节点的下一个节点while (current->next != *head) {current = current->next;}current->next = (*head)->next;*head = (*head)->next;}} else {int j = 1;// 找到第i个节点的前一个节点while (current->next != *head && j < i - 1) {current = current->next;j++;}// 如果没有找到第i个节点(即i大于链表长度)if (current->next == *head || j != i - 1) {printf("索引越界\n");return -1;}// 删除第i个节点toDelete = current->next;current->next = toDelete->next;}free(toDelete);return 0;
}
int main()
{int data1[] = {1 , 3 , 5, 7 , 9};int n1 = sizeof(data1)/ sizeof(data1[0]);int data2[] = {2, 4 , 6 , 8 , 10};int n2 = sizeof(data2)/ sizeof(data2[0]);LinkNode* head1 = createlistF(data1,n1);LinkNode* head2 = createlistR(data2,n2); //测试用例 //printflist(head1);//printflist(head2);//初始化LinkNode *head =NULL;initlist(&head);head = head1;//判断是否为空emptylist(head); //求长度int length = lengthlist(head);printf("线性表的长度为%d\n",length); //打印线性表printf("表为:");printflist(head);//线性表中第i个元素的值int elem = getelem(head,3);printf("第3个位置的值是%d\n",elem);//求第一个值为i的元素序号locatelist(head,9); //插入第i个元素insertlist(&head,3,6);printflist(head);//删除第i个元素deletelist(&head,2);printflist(head);//删除线性表 destroylist(&head);return 0;  
} 

5.实现双向循环链表的基本运算:

#include<stdio.h>
#include<stdlib.h>
typedef int ElemType;
typedef struct DNode
{ElemType data;struct DNode* prior;struct DNode* next;
}DLinkNode;
//头插法
DLinkNode* createlistF(int data[], int n)
{DLinkNode* head = NULL;DLinkNode* tail = NULL;int i = 0;for (i = 0; i < n; i++){DLinkNode* newNode = (DLinkNode*)malloc(sizeof(DLinkNode));if (newNode == NULL){printf("内存分配失败\n");return NULL;}newNode->data = data[i];if (head == NULL){head = newNode;tail = newNode;newNode->next = head;newNode->prior = head;}else{newNode->next = head;head->prior = newNode;newNode->prior = tail;tail->next = newNode;head = newNode;}}return head;
}
//尾插法实现
DLinkNode* createlistR(int data[], int n)
{DLinkNode* head = NULL;DLinkNode* tail = NULL;int i = 0;for (i = 0; i < n; i++){DLinkNode* newNode = (DLinkNode*)malloc(sizeof(DLinkNode));if (newNode == NULL){printf("内存分配失败\n");return NULL;}newNode->data = data[i];if (head == NULL){head = newNode;tail = newNode;newNode->next = head;newNode->prior = head;}else{newNode->prior = tail;tail->next = newNode;newNode->next = head;head->prior = newNode;tail = newNode;}}return head;
}
//初始化
void initlist(DLinkNode** head)
{*head = (DLinkNode*)malloc(sizeof(DLinkNode));(*head)->prior = (*head)->next = *head;
}
//打印链表 
void printflist(DLinkNode* head)
{DLinkNode* p = head;do{printf("%d ", p->data);p = p->next;} while (p != head);printf("\n");
}
//销毁线性表
void destroylist(DLinkNode** head)
{DLinkNode* current = *head;DLinkNode* next = NULL;while (current != NULL){next = current->next;free(current);current = next;}*head = NULL;
}
//判断是否为空
void emptylist(DLinkNode* head)
{if (head == NULL)printf("链表是空的\n");elseprintf("链表为非空\n");
}
//求长度
int lengthlist(DLinkNode* head)
{DLinkNode* p = head;int i = 0;do{i++;p = p->next;} while (p->next != head);return i;
}
//求值为i的元素序号
int locatelist(DLinkNode* head, int i)
{if (head == NULL){printf("链表为空\n");return -1;}int n = 1;DLinkNode* p = head;do{if (p->data == i){printf("%d的位置是%d\n", i, n);return n;}n++;p = p->next;} while (p != head);printf("%d不存在\n", i);return -1;
}
//插入第i个元素
int insertlist(DLinkNode** head, int i, int n)
{if (i < 1){printf("插入位置不合法\n");return -1;}DLinkNode* newNode = (DLinkNode*)malloc(sizeof(DLinkNode));if (!newNode) {printf("内存分配失败\n");return -1;}newNode->data = n;if (*head == NULL || i == 1){newNode->next = newNode;newNode->prior = newNode;if (*head != NULL){DLinkNode* tail = *head;while (tail->next != *head){tail = tail->next;}tail->next = newNode;newNode->prior = tail;}*head = newNode;return 0;}DLinkNode* current = *head;int j = 1;while (current->next != *head && j < i -1){current = current->next;j++;}if (j != i - 1) {printf("索引越界\n");free(newNode); // 释放新节点的内存return -1;}newNode->prior = current;newNode->next = current->next;current->next = newNode;return 0;
}
//删除第i个元素
int deletelist(DLinkNode** head, int i)
{if (*head == NULL || i < 1) {printf("链表为空或者位置不正确\n");return -1;}DLinkNode* current = *head;DLinkNode* todelete = NULL;if (i == 1){todelete = *head;if (current->next == head){*head == NULL;}else{while (current->next != head){current = current->next;}current->next = (*head)->next;*head = (*head)->next;(*head)->prior = current;}}else{int j = 1;while (current->next != *head && j < i - 1){current = current->next;j++;}if (current->next == *head || j != i - 1) {printf("索引越界\n");return -1;}todelete = current->next;current->next = todelete->next;todelete->next->prior = current;}free(todelete);return 0;
}
int main()
{int data1[]={1 , 3 , 5 , 7 , 9};int n1 = sizeof(data1)/ sizeof(data1[0]);int data2[]={2 , 4 , 6 , 8 , 10};int n2 = sizeof(data2)/ sizeof(data2[0]);DLinkNode* head1 = createlistF(data1,n1);DLinkNode* head2 = createlistR(data2,n2);//测试用例//printflist(head1); //printflist(head2);//初始化DLinkNode* head = NULL;initlist(&head);head = head1;//判断是否为空emptylist(head); //求长度int length = lengthlist(head);printf("线性表的长度为%d\n",length); //打印线性表printf("表为:");printflist(head);//求第一个值为i的元素序号locatelist(head,9); //插入第i个元素insertlist(&head,3,6);printflist(head);//删除第i个元素deletelist(&head,2);printflist(head);//删除线性表 destroylist(&head);return 0;
}

6.把单链表按基准划分:

#include<stdio.h>
#include<stdlib.h>
//创建节点 
typedef char ElemType;
typedef struct Node {ElemType data;struct Node* next;
}Node;
//将单链表以x为基准划分 
void Split(Node** head, ElemType x)
{Node* current = *head;Node* smallerHead = NULL;Node* smallerTail = NULL;Node* largerHead = NULL;Node* largerTail = NULL;while (current != NULL){if (current->data < x){if (smallerHead == NULL) {smallerHead = current;smallerTail = current;}else {smallerTail->next = current;smallerTail = current;}}else{if (largerHead == NULL) {largerHead = current;largerTail = current;}else {largerTail->next = current;largerTail = current;}}current = current->next;}if (smallerHead == NULL) {*head = largerHead;}else {smallerTail->next = largerHead;*head = smallerHead;}if (largerTail != NULL) {largerTail->next = NULL;}
}
//头插法创建一个单链表
Node* createlistf(int data[],int n)
{Node* head = NULL;int i = 0;for(i = 0; i < n; i++){Node* newNode = (Node*)malloc(sizeof(Node));if (newNode == NULL){printf("位置不合法");return NULL;}newNode->data = data[i];newNode->next = head;head = newNode;}return head;
} 
void destroylist(Node **head)
{Node *current = *head;Node *next = NULL;while (current != NULL){next = current->next;free(current);current = next;}*head = NULL;
}
void printflist(Node *head)
{Node *p = head;while (p != NULL){printf("%d ", p->data);p = p->next;}printf("\n");
}
int main()
{int data1[] = {1 , 3 , 5 , 7 , 9};int n1 = sizeof(data1) / sizeof(data1[0]);Node* head = createlistf(data1, n1);printflist(head);ElemType x = 7;printf("以7为基准划分:\n");Split(&head,x);printflist(head);return 0;
}

7.简单合并单链表(不涉及排序):

#include<stdio.h>
#include<stdlib.h>
//创建节点 
typedef char ElemType;
typedef struct Node {ElemType data;struct Node* next;
}Node;
//合并单链表
void merge(Node** head1, Node** head2, Node** head3)
{Node* p = *head1;Node* q = *head2;Node dummy; // 创建一个哑节点作为合并链表的开始Node* r = &dummy; // r指向哑节点while (q != NULL && p != NULL){r->next = p; // 将p节点连接到rp = p->next; // 移动p到下一个节点r = r->next; // 移动r到下一个节点r->next = q; // 将q节点连接到rq = q->next; // 移动q到下一个节点r = r->next; // 移动r到下一个节点 }if (p != NULL){r->next = p;}else if (q != NULL){r->next = q;}*head3 = dummy.next; // 设置head3为合并后链表的头节点
}
//头插法创建一个单链表
Node* createlistf(int data[],int n)
{Node* head = NULL;int i = 0;for(i = 0; i < n; i++){Node* newNode = (Node*)malloc(sizeof(Node));if (newNode == NULL){printf("位置不合法");return NULL;}newNode->data = data[i];newNode->next = head;head = newNode;}return head;
} 
void destroylist(Node **head)
{Node *current = *head;Node *next = NULL;while (current != NULL){next = current->next;free(current);current = next;}*head = NULL;
}
void printflist(Node *head)
{Node *p = head;while (p != NULL){printf("%d ", p->data);p = p->next;}printf("\n");
}
int main()
{int data1[] = {1 , 3 , 5 , 7 , 9};int n1 = sizeof(data1) / sizeof(data1[0]);int data2[] = {2 , 4 , 6 , 8 , 10};int n2 = sizeof(data2) / sizeof(data2[0]);Node* head1 = createlistf(data1, n1);Node* head2 = createlistf(data2, n2);Node* head3 = NULL;printf("合并为:\n");merge(&head1,&head2,&head3);printflist(head3);return 0;
}

8.合并单链表​(有序:小到大):

#include<stdio.h>
#include<stdlib.h>
​
//创建节点 
typedef char ElemType;
​
typedef struct Node {ElemType data;struct Node* next;
}Node;
​
//合并单链表
void merge(Node** head1, Node** head2, Node** head3)
{Node* p = *head1;Node* q = *head2;Node dummy; // 创建一个哑节点作为合并链表的开始Node* r = &dummy; // r指向哑节点while (q != NULL && p != NULL){if(p->data < q->data){r->next = p;p = p->next;}else{r->next = q;q = q->next;}r = r->next;}
​if (p != NULL){r->next = p;}else if (q != NULL){r->next = q;}
​*head3 = dummy.next; // 设置head3为合并后链表的头节点
}
​
Node* createlistr(int data[],int n)
{Node *head = NULL;;Node *tail = NULL;;int i = 0;for (i = 0; i < n; i++){Node* newNode = (Node*)malloc(sizeof(Node));if (newNode == NULL){printf("位置不合法");return NULL;}newNode->data = data[i];newNode->next = NULL;
​if (head == NULL){head = newNode;tail = newNode;}else{tail->next = newNode;tail = newNode;}} return head;
} 
​
void destroylist(Node **head)
{Node *current = *head;Node *next = NULL;while (current != NULL){next = current->next;free(current);current = next;}*head = NULL;
}
​
void printflist(Node *head)
{Node *p = head;while (p != NULL){printf("%d ", p->data);p = p->next;}printf("\n");
}
​
​
int main()
{int data1[] = {1 , 3 , 5 , 7 , 9};int n1 = sizeof(data1) / sizeof(data1[0]);int data2[] = {2 , 4 , 6 , 8 , 10};int n2 = sizeof(data2) / sizeof(data2[0]);
​Node* head1 = createlistr(data1, n1);Node* head2 = createlistr(data2, n2);Node* head3 = NULL;printf("合并为:\n");merge(&head1,&head2,&head3);printflist(head3);return 0;
}

​ 

9.用单链表实现交、并和差:

#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
​
#define MAX 100;
​
typedef struct
{double coef;  //系数int exp;    //指数
}PolyArray;
​
typedef struct pnode
{double coef;  //系数int exp;    //指数struct pnode* next;
}PolyNode;
​
//尾插法建立单链表
PolyNode* createlistR(PolyArray a[], int n)
{PolyNode* head = NULL;PolyNode* tail = NULL;
​int i = 0;for (i = 0; i < n; i++){PolyNode* newNode = (PolyNode*)malloc(sizeof(PolyNode));
​if (newNode == NULL){printf("位置不合法");return NULL;}
​newNode->coef = a[i].coef;newNode->exp = a[i].exp;
​newNode->next = NULL;
​
​if (head == NULL){head = newNode;tail = newNode;}else{tail->next = newNode;tail = newNode;}}return head;
}
​
//打印
void DispPoly(PolyNode* head)
{bool first = true;
​PolyNode* p = head;
​while (p != NULL){
​if (first){first = false;}else if (p->coef > 0){printf("+");}
​switch (p->exp){case 0:printf("%g", p->coef);break;case 1:printf("%gx", p->coef);break;default:printf("%gx^%d", p->coef, p->exp);break;}
​p = p->next;}
​printf("\n");
}
​
void Sort(PolyNode** head)
{if (*head == NULL || (*head)->next == NULL) {return; // 如果链表为空或只有一个节点,无需排序}
​bool swapped;PolyNode** ptr;do {swapped = false;ptr = head;
​while ((*ptr)->next != NULL) {if ((*ptr)->exp < (*ptr)->next->exp) {// 交换节点PolyNode* temp = *ptr;*ptr = (*ptr)->next;temp->next = (*ptr)->next;(*ptr)->next = temp;
​swapped = true;}ptr = &((*ptr)->next);}} while (swapped);
}
​
//销毁线性表
void destroylist(PolyNode** head)
{PolyNode* current = *head;PolyNode* next = NULL;
​while (current != NULL){next = current->next;free(current);current = next;}
​*head = NULL;
}
​
// 辅助函数:向结果多项式中添加项
void AddTerm(PolyNode** hc, double coef, int exp) {if (coef == 0) return; // 如果系数为0,直接返回,不添加
​PolyNode* newNode = (PolyNode*)malloc(sizeof(PolyNode));newNode->coef = coef;newNode->exp = exp;newNode->next = NULL;
​if (*hc == NULL || (*hc)->exp < exp) { // 如果链表为空或当前项指数大于链表头指数newNode->next = *hc;*hc = newNode;} else {PolyNode* prev = NULL;PolyNode* curr = *hc;while (curr != NULL && curr->exp > exp) {prev = curr;curr = curr->next;}if (curr != NULL && curr->exp == exp) { // 找到相同指数的项curr->coef += coef; // 合并系数if (curr->coef == 0) { // 如果合并后系数为0if (prev != NULL) {prev->next = curr->next; // 从链表中删除当前项} else {*hc = curr->next; // 更新头指针}free(curr); // 释放内存}free(newNode); // 释放新创建的节点,因为已经合并} else { // 没有找到相同指数的项,插入新项newNode->next = curr;if (prev != NULL) {prev->next = newNode;} else {*hc = newNode; // 更新头指针}}}
}
​
​
// 多项式乘法函数
void Mult(PolyNode* ha, PolyNode* hb, PolyNode** hc) {*hc = NULL; // 初始化结果多项式为空PolyNode* pa = ha;PolyNode* pb = NULL;
​while (pa != NULL) {pb = hb;while (pb != NULL) {// 计算乘积项的系数和指数double coef = pa->coef * pb->coef;int exp = pa->exp + pb->exp;// 将乘积项添加到结果多项式中AddTerm(hc, coef, exp);pb = pb->next;}pa = pa->next;}
}
​
​
int main()
{PolyArray a[] = { {2,1},{3,3} };PolyArray b[] = { {2,1},{3,3} };
​PolyNode* ha = createlistR(a, 2);PolyNode* hb = createlistR(b, 2);
​//打印printf("初始多项式:\n");DispPoly(ha);DispPoly(hb);
​
​Sort(&ha);Sort(&hb);printf("排序后多项式:\n");DispPoly(ha);DispPoly(hb);
​//多项式相乘 PolyNode* hc; Mult(ha,hb,&hc);printf("多项式相乘后:\n");DispPoly(hc);
​destroylist(&ha);destroylist(&hb);destroylist(&hc);
​return 0;
}

10.实现两个多项式相加:

#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
​
#define MAX 100;
​
typedef struct
{double coef;  //系数int exp;    //指数
}PolyArray;
​
typedef struct pnode
{double coef;  //系数int exp;    //指数struct pnode* next;
}PolyNode;
​
//尾插法建立单链表
PolyNode* createlistR(PolyArray a[], int n)
{PolyNode* head = NULL;PolyNode* tail = NULL;
​int i = 0;for (i = 0; i < n; i++){PolyNode* newNode = (PolyNode*)malloc(sizeof(PolyNode));
​if (newNode == NULL){printf("位置不合法");return NULL;}
​newNode->coef = a[i].coef;newNode->exp = a[i].exp;
​newNode->next = NULL;
​
​if (head == NULL){head = newNode;tail = newNode;}else{tail->next = newNode;tail = newNode;}}return head;
}
​
//打印
void DispPoly(PolyNode *head)
{bool first = true;
​PolyNode* p = head;
​while (p != NULL){
​if (first){first = false;}else if(p->coef > 0){printf("+");}
​switch (p->exp){case 0:printf("%g", p->coef);break;case 1:printf("%gx", p->coef);break;default:printf("%gx^%d", p->coef, p->exp);break;}p = p->next;}
​printf("\n");
}
​
void Sort(PolyNode **head)
{if (*head == NULL || (*head)->next == NULL) {return; // 如果链表为空或只有一个节点,无需排序}
​bool swapped;PolyNode **ptr;do {swapped = false;ptr = head;
​while ((*ptr)->next != NULL) {if ((*ptr)->exp < (*ptr)->next->exp) {// 交换节点PolyNode *temp = *ptr;*ptr = (*ptr)->next;temp->next = (*ptr)->next;(*ptr)->next = temp;
​swapped = true;}ptr = &((*ptr)->next);}} while (swapped);
}
​
// 向多项式中添加项
void AddTerm(PolyNode** head, double coef, int exp) {PolyNode* newNode = (PolyNode*)malloc(sizeof(PolyNode));newNode->coef = coef;newNode->exp = exp;newNode->next = NULL;
​if (*head == NULL) {*head = newNode;} else {PolyNode* temp = *head;while (temp->next != NULL) {temp = temp->next;}temp->next = newNode;}
}
​
// 多项式相加函数
void AddPolynomials(PolyNode* pa, PolyNode* pb, PolyNode** pc) {*pc = NULL; // 初始化结果多项式为空while (pa != NULL && pb != NULL) {if (pa->exp > pb->exp) {AddTerm(pc, pa->coef, pa->exp);pa = pa->next;} else if (pa->exp < pb->exp) {AddTerm(pc, pb->coef, pb->exp);pb = pb->next;} else {double sumCoef = pa->coef + pb->coef;if (sumCoef != 0) { // 如果系数和不为0,则添加到结果多项式中AddTerm(pc, sumCoef, pa->exp);}pa = pa->next;pb = pb->next;}}
​// 处理剩余项while (pa != NULL) {AddTerm(pc, pa->coef, pa->exp);pa = pa->next;}
​while (pb != NULL) {AddTerm(pc, pb->coef, pb->exp);pb = pb->next;}
}
​
//销毁线性表
void destroylist(PolyNode **head)
{PolyNode *current = *head;PolyNode *next = NULL;while (current != NULL){next = current->next;free(current);current = next;}*head = NULL;
}
​
int main()
{PolyArray a[] = { {1.2,0},{2.5,1},{3.2,3},{-2.5,5} };PolyArray b[] = { {-1.2,0},{2.5,1},{3.2,3},{2.5,5},{5.4,10} };
​PolyNode* ha = createlistR(a, 4);PolyNode* hb = createlistR(b, 5);
​//打印printf("初始多项式:\n");DispPoly(ha);DispPoly(hb); Sort(&ha);Sort(&hb);printf("排序后多项式:\n");DispPoly(ha);DispPoly(hb); 
​//多项式相加PolyNode* hc; AddPolynomials(ha,hb,&hc);printf("多项式相加后:\n");DispPoly(hc);destroylist(&ha);destroylist(&hb);destroylist(&hc);return 0;
}

​11.实现两个多项式相乘:

#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
​
#define MAX 100;
​
typedef struct
{double coef;  //系数int exp;    //指数
}PolyArray;
​
typedef struct pnode
{double coef;  //系数int exp;    //指数struct pnode* next;
}PolyNode;
​
//尾插法建立单链表
PolyNode* createlistR(PolyArray a[], int n)
{PolyNode* head = NULL;PolyNode* tail = NULL;
​int i = 0;for (i = 0; i < n; i++){PolyNode* newNode = (PolyNode*)malloc(sizeof(PolyNode));
​if (newNode == NULL){printf("位置不合法");return NULL;}
​newNode->coef = a[i].coef;newNode->exp = a[i].exp;
​newNode->next = NULL;
​
​if (head == NULL){head = newNode;tail = newNode;}else{tail->next = newNode;tail = newNode;}}return head;
}
​
//打印
void DispPoly(PolyNode* head)
{bool first = true;
​PolyNode* p = head;
​while (p != NULL){
​if (first){first = false;}else if (p->coef > 0){printf("+");}
​switch (p->exp){case 0:printf("%g", p->coef);break;case 1:printf("%gx", p->coef);break;default:printf("%gx^%d", p->coef, p->exp);break;}
​p = p->next;}
​printf("\n");
}
​
void Sort(PolyNode** head)
{if (*head == NULL || (*head)->next == NULL) {return; // 如果链表为空或只有一个节点,无需排序}
​bool swapped;PolyNode** ptr;do {swapped = false;ptr = head;
​while ((*ptr)->next != NULL) {if ((*ptr)->exp < (*ptr)->next->exp) {// 交换节点PolyNode* temp = *ptr;*ptr = (*ptr)->next;temp->next = (*ptr)->next;(*ptr)->next = temp;
​swapped = true;}ptr = &((*ptr)->next);}} while (swapped);
}
​
//销毁线性表
void destroylist(PolyNode** head)
{PolyNode* current = *head;PolyNode* next = NULL;
​while (current != NULL){next = current->next;free(current);current = next;}
​*head = NULL;
}
​
// 辅助函数:向结果多项式中添加项
void AddTerm(PolyNode** hc, double coef, int exp) {if (coef == 0) return; // 如果系数为0,直接返回,不添加
​PolyNode* newNode = (PolyNode*)malloc(sizeof(PolyNode));newNode->coef = coef;newNode->exp = exp;newNode->next = NULL;
​if (*hc == NULL || (*hc)->exp < exp) { // 如果链表为空或当前项指数大于链表头指数newNode->next = *hc;*hc = newNode;} else {PolyNode* prev = NULL;PolyNode* curr = *hc;while (curr != NULL && curr->exp > exp) {prev = curr;curr = curr->next;}if (curr != NULL && curr->exp == exp) { // 找到相同指数的项curr->coef += coef; // 合并系数if (curr->coef == 0) { // 如果合并后系数为0if (prev != NULL) {prev->next = curr->next; // 从链表中删除当前项} else {*hc = curr->next; // 更新头指针}free(curr); // 释放内存}free(newNode); // 释放新创建的节点,因为已经合并} else { // 没有找到相同指数的项,插入新项newNode->next = curr;if (prev != NULL) {prev->next = newNode;} else {*hc = newNode; // 更新头指针}}}
}
​
​
// 多项式乘法函数
void Mult(PolyNode* ha, PolyNode* hb, PolyNode** hc) {*hc = NULL; // 初始化结果多项式为空PolyNode* pa = ha;PolyNode* pb = NULL;
​while (pa != NULL) {pb = hb;while (pb != NULL) {// 计算乘积项的系数和指数double coef = pa->coef * pb->coef;int exp = pa->exp + pb->exp;// 将乘积项添加到结果多项式中AddTerm(hc, coef, exp);pb = pb->next;}pa = pa->next;}
}
​
​
int main()
{PolyArray a[] = { {2,1},{3,3} };PolyArray b[] = { {2,1},{3,3} };
​PolyNode* ha = createlistR(a, 2);PolyNode* hb = createlistR(b, 2);
​//打印printf("初始多项式:\n");DispPoly(ha);DispPoly(hb);
​
​Sort(&ha);Sort(&hb);printf("排序后多项式:\n");DispPoly(ha);DispPoly(hb);
​//多项式相乘 PolyNode* hc; Mult(ha,hb,&hc);printf("多项式相乘后:\n");DispPoly(hc);
​destroylist(&ha);destroylist(&hb);destroylist(&hc);
​return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/429163.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【永磁同步电机(PMSM)】 4. 坐标变换的 Matlab 仿真

【永磁同步电机&#xff08;PMSM&#xff09;】 4. 坐标变换的 Matlab 仿真 1. Clarke 变换的模型与仿真1.1 Clarke 变换1.2 Clarke 变换的仿真模型 2. Park 变换的模型与仿真2.1 Park 变换2.2 Park 变换的仿真模型 3. Simscape标准库变换模块3.1 abc to Alpha-Beta-Zero 模块3…

更换硬盘后,电脑装完系统进不去?或PE能识别硬盘但开机/启动/BIOS识别不了硬盘解决办法

由于现在的电脑主板&#xff0c;默认都是UEFI启动&#xff0c;硬盘只有使用GUID分区表&#xff0c;主板BIOS才找得到系统引导&#xff01; 而当我们拿到一块新硬盘&#xff0c;使用分区工具默认类型分区&#xff0c;默认是MBR类型&#xff0c;所以这种分区的硬盘&#xff0c;B…

14.面试算法-字符串常见算法题(三)

1. 字符串回文问题 1.1 LeetCode.125. 验证回文串 回文问题在链表中是重点&#xff0c;在字符串中同样是个重点。当初我去美团面试第一轮技术面的第一个算法题就是让写判断字符串回文的问题。 这个本身还是比较简单的&#xff0c;只要先转换成字符数组&#xff0c;然后使用双…

肺结节检测系统源码分享

肺结节检测检测系统源码分享 [一条龙教学YOLOV8标注好的数据集一键训练_70全套改进创新点发刊_Web前端展示] 1.研究背景与意义 项目参考AAAI Association for the Advancement of Artificial Intelligence 项目来源AACV Association for the Advancement of Computer Visio…

uniapp uview扩展u-picker支持日历期间 年期间 月期间 时分期间组件

uniapp uview扩展u-picker支持日历期间 年期间 月期间 时分期间组件 日历期间、年期间、月期间及时分期间组件在不同的应用场景中发挥着重要的作用。这些组件通常用于表单、应用程序或网站中&#xff0c;以方便用户输入和选择特定的日期和时间范围。以下是这些组件的主要作用&a…

C++:日期类的实现

目录 一、前言 二、头文件 三、各个函数的实现 打印、检查日期及获取日期 、、-、-、 、<、<、>、>、 &#xff01; 日期-日期 >>、<< 一、前言 前面几篇讲了关于类和对象的一些知识&#xff0c;本篇就来实现一下前面用到的日期类。 二、头文…

TryHackMe 第3天 | Pre Security (中)

该学习路径讲解了网络安全入门的必备技术知识&#xff0c;比如计算机网络、网络协议、Linux命令、Windows设置等内容。上一篇中简短介绍了计算机网络相关的知识&#xff0c;本篇博客将记录 网络协议 部分。 How the web works? DNS in detail DNS (Domain name system&…

Java面试篇-AOP专题(什么是AOP、AOP的几个核心概念、AOP的常用场景、使用AOP记录操作日志、Spring中的事务是如何实现的)

文章目录 1. 什么是AOP2. AOP的几个核心概念3. AOP的常用场景4. 使用AOP记录操作日志4.1 准备工作4.1.1 引入Maven依赖4.1.2 UserController.java4.1.3 User.java4.1.4 UserService.java 4.2 具体实现&#xff08;以根据id查询用户信息为例&#xff09;4.2.1 定义切面类&#x…

SkyWalking 环境搭建部署

架构简介 skywalking agent : 和业务系统绑定在一起,负责收集各种监控数据skywalking oapservice : 是负责处理监控数据的,比如接受skywalking agent的监控数据,并存储在数据库中;接受skywalking webapp的前端请求,从数据库查询数据,并返回数据给前端。Skywalking oapserv…

华为HarmonyOS地图服务 7- 在地图上绘制标记

场景介绍 本章节将向您介绍如何在地图的指定位置添加标记以标识位置、商家、建筑等。 点标记用来在地图上标记任何位置,例如用户位置、车辆位置、店铺位置等一切带有位置属性的事物。Map Kit提供的点标记功能(又称 Marker)封装了大量的触发事件,例如点击事件、长按事件、…

【RabbitMQ】消息分发、事务

消息分发 概念 RabbitMQ队列拥有多个消费者时&#xff0c;队列会把收到的消息分派给不同的消费者。每条消息只会发送给订阅该队列订阅列表里的一个消费者。这种方式非常适合扩展&#xff0c;如果现在负载加重&#xff0c;那么只需要创建更多的消费者来消费处理消息即可。 默…

linux网络编程5

24.9.21学习目录 一.TCP1.TCP流程2.TCP相关函数3.三次握手 一.TCP 1.TCP流程 服务器流程&#xff1a; 创建套接字socket&#xff08;&#xff09;将套接字与服务器网络信息结构体绑定bind&#xff08;&#xff09;将套接字设置为监听状态listen&#xff08;&#xff09;阻塞等…

进程间的通信4 共享内存

共享内存 1.共享内存简介 共享内存是将分配的物理空间直接映射到进程的用户虚拟地址空间中&#xff0c;减少数据在内核空间缓存共享内存是一种效率较高的进程间通讯的方式在 Linux 系统中通过 ipcs -m 查看所有的共享内存 共享内存模型图 2.共享内存的创建 1.函数头文件 #…

Java算法专栏

专栏导读 在当今这个技术日新月异的时代&#xff0c;Java算法作为软件开发的核心&#xff0c;对于提升程序性能和解决复杂问题至关重要。本“Java算法”专栏旨在帮助读者深入理解Java编程语言中的算法原理和应用&#xff0c;通过实战案例和深入分析&#xff0c;使读者能够掌握…

Java汽车销售管理

技术架构&#xff1a; springboot mybatis Mysql5.7 vue2 npm node 功能描述&#xff1a; 针对汽车销售提供客户信息、车辆信息、订单信息、销售人员管理、财务报表等功能&#xff0c;提供经理和销售两种角色进行管理 效果图&#xff1a;

Python基础学习(3)

目录 一&#xff0c;函数 1&#xff0c;函数的定义 2&#xff0c;函数的参数 1&#xff0c;默认值 2&#xff0c;传参 3&#xff0c;返回值 4&#xff0c;变量的作用域 5&#xff0c;函数的调用 二&#xff0c;常用数据结构 1&#xff0c;列表 列表的定义 列表的特性…

【Geoserver使用】REST API调用(工作空间部分)

文章目录 前言一、Geoserver REST API(GeoServer Workspace)二、GeoServer Workspace接口使用1.GET请求 /workspaces2.POST请求 /workspaces3.GET请求 /workspaces/{workspaceName}4.PUT /workspaces/{workspaceName}5.DELETE /workspaces/{workspaceName} 总结 前言 根据Geos…

C++ | Leetcode C++题解之第423题从英文中重建数字

题目&#xff1a; 题解&#xff1a; class Solution { public:string originalDigits(string s) {unordered_map<char, int> c;for (char ch: s) {c[ch];}vector<int> cnt(10);cnt[0] c[z];cnt[2] c[w];cnt[4] c[u];cnt[6] c[x];cnt[8] c[g];cnt[3] c[h] - …

YOLOv10 简介

YOLOv10&#xff0c;由清华大学的研究人员基于 Ultralytics Python 包构建&#xff0c;引入了一种全新的实时目标检测方法&#xff0c;该方法解决了以往 YOLO 版本中后处理和模型架构方面的不足。通过消除非极大值抑制&#xff08;NMS&#xff09;并优化各种模型组件&#xff0…

【解决】chrome 谷歌浏览器,鼠标点击任何区域都是 Input 输入框的状态,能看到输入的光标

chrome 谷歌浏览器&#xff0c;鼠标点击任何区域都是 Input 输入框的状态&#xff0c;能看到输入的光标 今天打开电脑的时候&#xff0c;网页中任何文本的地方&#xff0c;只要鼠标点击&#xff0c;就会出现一个输入的光标&#xff0c;无论在哪个站点哪个页面都是如此。 我知道…