Question: Using the following class definitions, write a count method for the LinkedList class, that takes a list cargo item as an argument and returns the

Using the following class definitions, write a count method for the LinkedList class,

that takes a list cargo item as an argument and returns the number of times the item

occurs in the list.

class Node:

def __init__(self, cargo=None, next=None):

self.cargo = cargo

self.next = next

def __str__(self):

return str(self.cargo)

class LinkedList:

def __init__(self):

self.length = 0

self.head = None

def addFirst(self, cargo):

node = Node(cargo)

node.next = self.head

self.head = node

self.length = self.length + 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!