データ構造のチェーンテーブル(python実装)


#-*- coding : utf-8 -*-
"""
create on 2020/8/20 20:17
filename:lianbiao.py
"""
#      
#    
#    
class Node:
    def __init__(self,data = None, next = None):
        self.data = data
        self.next = next
#      
node1=Node(1)
node2=Node(2)
node3=Node(3)

node1.next=node2
node2.next=node3
print(node1.data)
#      
head=None
for count in range(1,6):
    head = Node(count, head)
while head != None:
    print(head.data)
    head = head.next
#    
probe = head
while probe != None:
    probe = probe.next
#      
probe = head
item=4
while(probe!=None&item != probe.data):
    probe = probe.next
if probe != None:
    print("found")
else:
    print("not found")
#      
index=2
probe=head
while(index > 0):
    probe = probe.next
    index -= 1
print(probe.data)
#      
probe=head
item=3
newitem=30
while(probe!=None&item!=probe.data):
    probe=probe.next
if(probe!=None):
    probe.data=newitem
else:
    print("not found")

#     
head=Node(newitem,head)
#      
if head is None or index <=0:
    head =Node(newitem, head)
else:
    probe = head
    while index > 1 and probe.next != None:
        probe = probe.next
        index -= 1
    probe.next = Node(newitem, probe.next)
#    
nNode=Node(newitem)
if(head is None):
    head=newitem
else:
    probe=head
    while(probe.next!=None):
        probe=probe.next
    probe.next=nNode

#     
head=head.next
#    
if index <= 0 or head.next is None:
    head = head.next
else:
    probe = head
    while index > 1 and probe.next.next != None:
        probe = probe.next
        index -= 1
    probe.next = probe.next.next
#    
if(head.next is None):
    head=None
else:
    probe=head
    while(probe.next!=None):
        probe=probe.next
    probe.next=None