## Question

## Transcribed Text

## Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

from recursioncounter import RecursionCounter"""

CourseList class implements

linked list data structure to store course object.

"""

class CourseList:

def __init__(self):

"""

CourseList constructor

"""

self.head = None

self.__tmp = None

def insert(self, course):

"""

This method inserts new course in the list

:param course: the course to be inserted

:return: None

"""

self.head = self.insert_helper(self.head, None, course)

def insert_helper(self, node, prev_node, course):

"""

Helper method to insert new course in the list.

:param node: the current node of the list.

:param prev_node: the previously traversed node

:param course: the course to be inserted.

:return: the inserted node.

"""

RecursionCounter()

if node is None:

return course

if node.number() > course.number():

if prev_node is not None:

course.next = node

prev_node.next = course

return course

else:

course.next = node

self.head = course

return course

node.next = self.insert_helper(node.next, node, course)

return node

def remove(self, number):

"""

Removes the first occurrence of the specified Course.

:param number: the number to be removed.

:return: None

"""

self.remove_helper(self.head, None, number)

def remove_helper(self, node, prev_node, number):

"""

Removes the first occurrence of the specified Course.

:param node: the currently traversed node.

:param prev_node: the previously traversed node.

:param number: the number to be removed.

:return: None

"""

RecursionCounter()

if node is None:

return

elif node.number() == number:

if prev_node is not None:

prev_node.next = node.next

else:

self.head = node.next

del node

else:

self.remove_helper(node.next, node, number)

def remove_all(self, number):

"""

Removes all occurrence of the specified Course.

:param number: the number to be removed.

:return: None

"""

self.remove_all_helper(self.head, None, number)

def remove_all_helper(self, node, prev_node, number):

"""

Removes all occurrence of the specified Course.

:param node: the currently traversed node.

:param prev_node: the previously traversed node.

:param number: the number to be removed.

:return: None

"""

RecursionCounter()

if node is None:

return

elif node.number() == number:

if prev_node is not None:

prev_node.next = node.next

self.remove_all_helper(node.next, prev_node, number)

else:

self.head = node.next

self.remove_all_helper(node.next, self.head, number)

del node

else:

self.remove_all_helper(node.next, node, number)

def find(self, number):

"""

Finds the course having the same given number.

:param number: the number to be searched.

:return: the course if found otherwise returns -1

"""

return self.find_helper(self.head, number)

def find_helper(self, node, number):

"""...

By purchasing this solution you'll be able to access the following files:

Solution.zip.