设为首页 加入收藏

TOP

237. Delete Node in a Linked List
2017-10-12 17:39:39 】 浏览:2721
Tags:237. Delete Node Linked List

Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.

Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, the linked list should become 1 -> 2 -> 4 after calling your function.

 

 1 /**
 2  * Definition for singly-linked list.
 3  * struct ListNode {
 4  *     int val;
 5  *     struct ListNode *next;
 6  * };
 7  */
 8 void deleteNode(struct ListNode* node) {
 9     if(node == NULL || node->next == NULL)             
10         return;
11     node->val = node->next->val;                       //把下一节点值赋予删除当前节点
12     node->next = node->next->next;                     //删除下一个节点
13 }

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇原创 单片机实验 下一篇关于Linux动态库的相关知识

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目