删除子结点

//删除所有子结点的方法
Procedure TCT_WJJG.DelAllChildrenNode(FNodeID:string);
var
  sqlStr: String;
begin
    sqlStr:=' delete GY_SB_WJJG where id in('
             +' select id from GY_SB_WJJG'
             +' start with id ='''+FNodeID+''''
             +' connect by prior  id= fid'
             +'  )';
    if (TZYJ_SJJCZHS.executeSqlWithReturn(sqlStr)) then
     begin
        DataSetBroker_WJJGS.DataSet.Refresh ;
     end;
end;

好的,我很乐意为您介绍如何使用C语言实现头插法和尾插法建立链表,并实现循环删除子节点。以下是实现这些功能的代码示例: ```c #include <stdio.h> #include <stdlib.h> // 定义链表节点结构 struct Node { int data; struct Node* next; }; // 头插法创建链表 struct Node* createListHead(int arr[], int n) { struct Node* head = NULL; for (int i = 0; i < n; i++) { struct Node* newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->data = arr[i]; newNode->next = head; head = newNode; } return head; } // 尾插法创建链表 struct Node* createListTail(int arr[], int n) { struct Node* head = NULL, *tail = NULL; for (int i = 0; i < n; i++) { struct Node* newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->data = arr[i]; newNode->next = NULL; if (head == NULL) { head = newNode; tail = newNode; } else { tail->next = newNode; tail = newNode; } } return head; } // 循环删除子节点 void deleteChildNodes(struct Node* head) { if (head == NULL) return; struct Node* current = head; while (current != NULL) { struct Node* temp = current->next; while (temp != NULL && temp->data == current->data) { current->next = temp->next; free(temp); temp = current->next; } current = current->next; } } // 打印链表 void printList(struct Node* head) { struct Node* current = head; while (current != NULL) { printf("%d -> ", current->data); current = current->next; } printf("NULL\n"); } // 主函数演示 int main() { int arr[] = {1, 2, 2, 3, 2, 4, 4, 4}; int n = sizeof(arr) / sizeof(arr[0]); // 使用头插法创建链表 struct Node* head1 = createListHead(arr, n); printf("头插法创建的链表:\n"); printList(head1); // 循环删除子节点 deleteChildNodes(head1); printf("删除子节点后的链表:\n"); printList(head1); // 使用尾插法创建链表 struct Node* head2 = createListTail(arr, n); printf("\n尾插法创建的链表:\n"); printList(head2); // 循环删除子节点 deleteChildNodes(head2); printf("删除子节点后的链表:\n"); printList(head2); return 0; } ``` 这段代码实现了以下功能: 1. 使用头插法和尾插法创建链表。 2. 实现了循环删除子节点的功能。 3. 包含打印链表的功能以便于观察结果。 代码的主要逻辑如下: - `createListHead` 函数使用头插法创建链表。 - `createListTail` 函数使用尾插法创建链表。 - `deleteChildNodes` 函数用于循环删除子节点。它会遍历链表,对于每个节点,删除所有值相同的连续节点。 - `printList` 函数用于打印链表。 在 `main` 函数中,我们首先创建一个包含重复元素的数组,然后分别使用头插法和尾插法创建链表,并打印结果。接着,我们调用 `deleteChildNodes` 函数删除子节点,并再次打印链表以观察结果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值