"""
单链表
1、计算长度操作
2、判断是否为空链表
3、头插法
4、尾插法
5、根据位置插入值
6、遍历链表
7、清空链表
8、根据位置删除链表值
9、根据值删除
10、链表逆序遍历
"""
class Node(object):
def __init__(self, value):
self.value = value
self.node = None
class LinkList(object):
def __init__(self, node):
self.__head = node
def __len__(self):
length = 0
curr = self.__head
while curr:
length += 1
curr = curr.next
return length
def is_empty(self):
"""
linklist is None
:return:
"""
return self.__head == None
def add(self, value):
"""
head insert
:param value:
:return:
"""
if value:
node = Node(value)
node.next = self.__head
self.__head = node
def append(self, value):
python 操作单链表(插入、删除、遍历)
最新推荐文章于 2024-07-17 17:25:16 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)