连表更新


update 表1 set 表1.Name=表2.Name from 表2 where 表1.Id=表2.Id 
需求是将表2中的Name字段内的数据更新到表1中的Name当中,数据源是表2,条件是表1的Id=表2的Id

以下是单循环链表的更新代码示例,包括在指定位置插入节点、删除指定位置节点和修改指定位置节点的值: ``` // 定义单循环链表节点结构体 typedef struct Node { int data; struct Node *next; } Node; // 在指定位置插入节点 void insertNode(Node **head, int pos, int val) { Node *newNode = (Node*)malloc(sizeof(Node)); newNode->data = val; newNode->next = NULL; if (*head == NULL) { // 链表为空 *head = newNode; (*head)->next = *head; return; } if (pos == 1) { // 在头部插入节点 newNode->next = *head; Node *tail = *head; while (tail->next != *head) { tail = tail->next; } tail->next = newNode; *head = newNode; return; } Node *prev = NULL; Node *curr = *head; int i = 1; while (i < pos && curr->next != *head) { // 在指定位置插入节点 prev = curr; curr = curr->next; i++; } prev->next = newNode; newNode->next = curr; } // 删除指定位置节点 void deleteNode(Node **head, int pos) { if (*head == NULL) { // 链表为空 return; } if (pos == 1) { // 删除头节点 Node *tail = *head; while (tail->next != *head) { tail = tail->next; } *head = (*head)->next; tail->next = *head; free(*head); return; } Node *prev = NULL; Node *curr = *head; int i = 1; while (i < pos && curr->next != *head) { // 删除指定位置节点 prev = curr; curr = curr->next; i++; } if (curr->next == *head) { // 如果删除的是尾节点 prev->next = *head; free(curr); } else { prev->next = curr->next; free(curr); } } // 修改指定位置节点的值 void modifyNode(Node *head, int pos, int val) { if (head == NULL) { // 链表为空 return; } Node *curr = head; int i = 1; while (i < pos && curr->next != head) { // 找到指定位置节点 curr = curr->next; i++; } if (i == pos) { // 找到节点 curr->data = val; } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值