Added method to return the length of a linked list.

This commit is contained in:
Donne Martin
2015-05-14 07:34:35 -04:00
parent ddbff0dab7
commit f52450363b
2 changed files with 50 additions and 1 deletions

View File

@@ -10,6 +10,14 @@ class Node(object):
class LinkedList(object):
def __init__(self, head=None):
self.head = head
def __len__(self):
curr = self.head
counter = 0
while curr is not None:
counter += 1
curr = curr.next
return counter
def insert_to_front(self, data):
if data is None: