Find size of Doubly Linked List

class Nodes:

def __init__(self):

self.data = None

self.next = None

self.prev = None

def push( ref, new_data):

new_node = Nodes()

new_node.data = new_data

new_node.next = (ref)

new_node.prev = None

if ((ref) != None):

(ref).prev = new_node

(ref) = new_node

return ref

def findSize(node):

res = 0

while (node != None):

res = res + 1

node = node.next

return res

head = None

head = push(head, 4)

head = push(head, 3)

head = push(head, 2)

head = push(head, 1)

print(findSize(head))


No comments: