python利用头插法将列表a=[0,1,2,3,4,5,6]插入到单向循环链表
时间: 2023-10-03 11:10:25 浏览: 74
的头部
```python
class Node:
def __init__(self, data=None, next=None):
self.data = data
self.next = next
class CircularLinkedList:
def __init__(self):
self.head = None
def insert_at_beginning(self, data):
node = Node(data, None)
if not self.head:
node.next = node
self.head = node
else:
curr = self.head
while curr.next != self.head:
curr = curr.next
node.next = self.head
curr.next = node
self.head = node
a = [0,1,2,3,4,5,6]
circular_list = CircularLinkedList()
for i in a:
circular_list.insert_at_beginning(i)
```
阅读全文