Ch2-3: remove the middle node in a singly linked list
来源:互联网 发布:2017女生标准体重算法 编辑:程序博客网 时间:2024/05/05 09:43
Implement an algorithm to delete a node in the middle of a single linked list, given only access to that node.
EXAMPLE
Input: the node ‘c’ from the linked list a->b->c->d->e Result: nothing is returned, but the new linked list looks like a->b->d->e
Solution:
Since only the removed node of the singly linked list is given, we can only find all the next but not going back. So we can copy the next node of this removable node so as to "remove" it.
One thing should notice is the corner condition:
1. head 2. middle 3. last one
for 1,2 is fine. For 3, we cannot use this method so can't solve it.
Here is the fully code:
Output:
Executing the program....$demo 10 9 8 7 6 5 4 3 2 1 10 9 7 6 5 4 3 2 1
0 0
- Ch2-3: remove the middle node in a singly linked list
- LinkedList---Delete Node in the Middle of Singly Linked List
- #372 Delete Node in the Middle of Singly Linked List
- Delete Node in the Middle of Singly Linked List
- Ch2-2: return the nth to the last node data of a singly linked list
- LintCode 372: Delete Node in the Middle of Singly Linked List
- LintCode Delete Node in the Middle of Singly Linked List 在O(1)时间复杂度删除链表节点
- 【11】Delete a node in the middle of a single linked list
- [CrackCode] 2.3 Delete a node in the middle of a single linked list
- fwnx - find the middle node in the linked list ~~~
- 372.Delete Node in the Middle of Singly Linked List-在O(1)时间复杂度删除链表节点(容易题)
- 1007. Find the middle element in a Linked List
- Q.2.3 Implement an algorithm to delete a node in the middle of a single linked list, given only acce
- Finding a Loop in a Singly Linked List
- Ch2-5: find the beginning of loop in a circular linked list---two solutions
- FW:Reverse a Singly Linked List Recursively in Java
- leetcode- Delete Node in a Linked List&Remove Linked List Elements
- (重点)Remove Linked List Elements和Delete Node in a Linked List
- Spring 中的TransactionTemplate
- object-c 不定参数的实现(摘自Typhoon)
- 【深入Java虚拟机】之八:Java垃圾收集机制
- 电脑突发故障应急处理方法
- 关于spring的配置文件applicationcontext.xml
- Ch2-3: remove the middle node in a singly linked list
- 电源引起的内存报警故障
- Python字典按值排序、包含字典的列表按字典值排序的方法
- Java垃圾回收机制----GC
- 面试总会问道的sql语句查询重复记录
- hdu 1890 Robotic Sort(Splay)
- oracle直接调用web services
- 电脑内存常见问题处理方法
- 调试技巧MFC中TRACE宏的使用