双向循环链表是在双链表的基础上建立的,其基础操作除了建立双向循环链表类有所不同外,其余均相同。
以下是双向循环链表类的代码:
class CDLinkList:#双向循环链表
def __init__(self):
self.dhead=DLinkNode()
self.dhead.next=self.dhead#初始化头结点的next域指向本身
self.dhead.prior=self.dhead#初始化头结点的prior域指向本身