# -*- coding: utf-8 -*-
"""
Created on Tue Feb 28 09:10:19 2017
@author: zzpp220
"""
class LinkList:
def __init__(self,val,link=None):
self.val=val
self.link=link
def __del__(self):
self.link=None
self.val=None
class DelNode:
def delNodeInO_1(self,link_head,toBeDeled):
if not link_head or not toBeDeled or(link_head.link==None and link_head!=toBeDeled):#special codition
return False
if link_head.val and link_head.link==None and link_head==toBeDeled:
link_head.__del__()
return 'Done'
if toBeDeled.link==None:##end node
pNode=link_head
while pNode.link!=toBeDeled:
pNode=pNode.link
pNode.link=None
toBeDeled.__del__()
else:##non-end node
pnext=toBeDeled.link
toBeDeled.val=pnext.val
toBeDeled.link=pnext.link
pnext.__del__()
if __name__=="__main__":
l1=LinkList(4)
l2=LinkList(3,l1)
l3=LinkList(2,l2)
l4=LinkList(1,l3)
solution=DelNode()
print solution.delNodeInO_1(l1,None)#(None,l4),(l4,l4),(l4,l1),(l1,l1),(l1,None)
print l4.val,l4.link.val,l4.link.link.val