$29.99
CISC-235 Data Structures
Assignment 1.1
1 Problem Context: ADT Bag
In class, we defined an Abstract Data Type called “Bag”. A bag is a container
for a group of data items. It has two main features:
1) The positions of the data items don’t matter.
2) The items do not need to be unique (unlike a set).
The Bag ADT also defines six operations applied on the data stored in the
bag:
1) add(item): add item to the Bag
2) remove(item): remove one occurrence of item (if any) from the Bag.
3) contains(item): check if item is in the Bag.
4) numItem s(): get the number of items in the Bag
5) grab(): get an item at random, without removing it.
6) str (): get a string representing the current contents of the bag.
2 Assignment Requirements
Your assignment is to create a class in Python/Java/C++ to implement the details of the six operations defined in Section 1 and write a test to demostrate the
correctness of your function. For instance, to demostrate that your add(item)
is correct, you need to print the data items in the bag before and after running
this function. You are only allowed to use the build-in libraries and modules provided by Python/Java/C++. Your test code should be put in a main
function.
If you are writing Python code, you must put your test code inside a main
function:
1
def main():
[your test code]
if __name__== ’__main__’:
main()
Deadline: By the end of next Wednesday (Jan-16,2019)
Where to submit: OnQ
What to submit: You should upload your runnable source code (one file containing Bag ADT implementation and test code). I don’t need extra document
as we are not doing any algorithm analysis for this task.
2