Simple and easy way of explanation to get good marks in your academy Educational advancement for the benefit of the public charity In general, to ‘advance’ education means to promote, sustain and increase individual and collective knowledge and understanding of specific areas of study, skills and expertise.
class _Node:
ReplyDelete__slots__ = '_element', '_next', '_prev'
def __init__(self, element, next, prev):
self._element = element
self._next = next
self._prev = prev
class DoublyLinkedList:
def __init__(self):
self._head = None
self._tail = None
self._size = 0
def __len__(self):
return self._size
def isempty(self):
return self._size == 0
def addlast(self, e):
newest = _Node(e, None, None)
if self.isempty():
self._head = newest
self._tail = newest
else:
self._tail._next = newest
newest._prev = self._tail
self._tail = newest
self._size += 1
def display(self):
p = self._head
while p:
print(p._element,end=' --> ')
p = p._next
print()
def displayrev(self):
p = self._tail
while p:
print(p._element,end=' <-- ')
p = p._prev
print()
L = DoublyLinkedList()
L.addlast(7)
L.addlast(4)
L.addlast(12)
L.addlast(8)
L.addlast(3)
L.display()
print('Size:',len(L))
L.displayrev()
output
ReplyDelete7 --> 4 --> 12 --> 8 --> 3 -->
Size: 5
3 <-- 8 <-- 12 <-- 4 <-- 7 <--