0

I need to make a linked list and the constructor has these requirements:

  1. init(self, head) • The constructor. We’ll have 3 attributes: head, tail, and count. • Make it so we can pass a reference to a node to create an OurLinkedList. • This means that we can by default create an empty list (nothing is passed to the constructor), OR start with an arbitrarily large linked structure (a reference to a node is passed to the constructor).

im having trouble understanding how and when to make objects in my code this is what i have so far:

def __init__(self, head):
    self.head= head
    a= OurLinkedList(self.head)

    curNode= self.head
    self.count= 0

    while curNode is not None:
        self.count += 1
        curNode= curNode.next

    self.tail= curNode  

and I get RecursionError: maximum recursion depth exceeded while calling a Python object

  • Possible duplicate of [Python Linked List](https://stackoverflow.com/questions/280243/python-linked-list) – Derek Brown Feb 23 '18 at 05:25
  • Please provide a [Minimal, Complete and Verifiable Example](https://stackoverflow.com/help/mcve) so we are able to assist. If that `__init__` function is for your `OurLinkedList` class, then the `__init__` function will not return - it will create `a`, which creates `a.a`, which creates `a.a.a` and so on until the recursion depth is exceeded. – import random Feb 23 '18 at 06:21

0 Answers0