Question: You will implement a custom MultiSet class using a sorted singly linked list as the storage mechanism. A MultiSet is a collection of elements that
You will implement a custom MultiSet class using a sorted singly linked list as the storage mechanism. A MultiSet is a collection of elements that allows duplicates and keeps track of the count of each element.
Initial Code Segment:
You will be using the following skeleton code in your assignment. Class and method names, and initial comments are given for you.
class Node:
def initself value, count:
Initialize a node with a value and a count."""
self.value value
self.count count
self.next None
class MultiSetClass:
def initself:
Initialize an empty multiset using a linked list."""
self.head None
def addself element:
Add an element to the multiset."""
pass
def removeself element:
Remove one occurrence of the specified element from the
multiset."""
passdef countself element:
Return the count of occurrences of the specified
element."""
pass
def lenself:
Return the total number of elements in the multiset
including duplicates
pass
def containsself element:
Check if an element exists in the multiset."""
pass
def reprself:
pass
Return a string representation of the multiset."""
def unionself other:
Return a new MultiSet that is the union of this and
another MultiSet."""
pass
def intersectionself other:
Return a new MultiSet that is the intersection of this
and another MultiSet."""
pass
def addself other:
Overload the operator to combine two multisets."""
pass
def subself other:Overload the operator to subtract one multiset from
another."""
pass
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
