c - 如果我使用 memmove() (在 C 中)删除链表中的节点,它会更有效吗?
问题描述
我在互联网上遇到的每个关于删除链表中节点的示例,他们都使用这种方法删除第一个节点:
Algorithm to delete first node of Singly Linked List
%%Input: head of the linked list
Begin:
If (head != NULL) then
toDelete ← head
head ← head.next
unalloc (toDelete)
End if
End
在这段代码中,他们从那里的列表中删除了第一个节点后释放了内存区域。但我使用 memove() 删除链表的第一个节点。
...
if (key == 1){
memmove(head, head->next, sizeof(node));
return;
}
...
那么,当我使用 memmove() 时,它会自动释放内存区域吗?我的代码效率更高吗?
解决方案
在您的代码头中是一个指针,它是一个标量,因此使用memmove不会比简单的赋值更快。memmove函数在复制较大的对象时很有用。
推荐阅读
- javascript - 电子应用程序:如何使 dialog.showOpenDialog 模态
- datatables - 数据表 - 隐藏数据直到搜索
- arrays - 如何访问数据框列中的数组元素(scala)
- accessibility - Jaws 快捷键,用于将焦点从 JAWS 查找对话框转移到搜索词出现
- javascript - 文本输入不为空时启用表单提交按钮的最简单方法
- amazon-web-services - 创建 DMS 复制实例时选择 VPC
- sql-server - 如何使用 sql server 创建与具有等级或任何其他功能的更改日期时间相关联的序列号
- javascript - 位置 1 处的 JSON 中的意外标记
- ignite - 点燃 AffinityKeyMapped 和 AffinityKeyMapper
- apache-kafka - 如何将Kafka中的Consumer分配给特定分区;在我的情况下,分区是通过Key的哈希值分配的