单链表是一种常见的数据结构也是学习数据结构入门时期遇到的第一个有挑战性且较困难的问题本文主要阐述单链表代码实现
废话不多说我们直接上代码(python语言)
class Node:
def __init__(self, data=None):
self.data = data
self.next = None
class SingleNode:
def __init__(self):
self.Head = Node(" ")
def __isempty__(self):
if self.Head.next is None:
print('当前链表为空')
def __len__(self):
cur = self.Head
count = 0
while cur.next is not None:
count += 1
cur = cur.next
return count
def __add_tail__(self, data):
node = Node(data)
temp = Node()
temp = self.Head
while 1:
if temp.next is None:
temp.next = node
break
temp = temp.next
temp = node
def __append__(self, data):
node = Node(data)
if self.__i