class ListNode(object): def __init__(self,data): self.data=data self.next=None class LinkList(object): def __init__(self): self.head=ListNode(None)#头节点 def Empty(self):#判空 if self.head.next==None: return True else: return False def initwei(self,e):#尾插 p=self.head while p.next: p=p.next q = ListNode(e) p.next=q def inittou(self,e):#头插 q = ListNode(e) q.next=self.head self.head=q def Get(self,i):#查找第i个点 if self.Empty(): return None j=0 p=self.head while p.next!=None and j<i: p=p.next j+=1 if j==i: return p.data else: return None def prit(self): p = self.head while p.next != None: print(p.next.data) p=p.next print(' ') def delet(self, index): count = 0 cur = self.head while cur.next and count < index - 1: count += 1 cur = cur.next if not cur: return 'Error' del_node = cur.next cur.next = del_node.next if __name__=='__main__': mylist_A=LinkList() for i in range(0, 6): print('input value:') n=int(input()) mylist_A.initwei(n) mylist_A.prit() print('input a place to search:') n = int(input()) qq = mylist_A.Get(n) print(qq) print(' ') print('input a place to delete:') n = int(input()) mylist_A.delet(n) mylist_A.prit() print(' ')