Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

ECS 32B: Intro to Data Structure

Homework Assignment 2

Submission: Please solve all the questions in this document in Python 3 and submit your solutions via Canvas.

Please submit one .py file for each question. For example, you should submit “hw2-1.py” for Question 1, “hw2-2.py” for Question2, and so on.

Please test your .py files and make sure they are executable before submission (You should      already know how to do it from your ECS32A or ECS10 course). Note that Python is a             programming language sensitive to space and indentation, so use a code editor (e.g., VS Code, PyCharm, Xcode …) rather than a text editor to edit your .py files.

Code of Conduct This homework is to be worked alone.

Each question will be entirely graded by a single grader, so it is easy to notice identical or highly similar answers. Copying (wholly or partially) a solution provided by a tutor or found on the       Internet also crosses the line into academic misconduct. Any suspicion of cheating beyond          reasonable doubt, will be reported to SJA and might incur academic and disciplinary sanctions.

Question 1 Use Python to implement a VotingMachine class that can be used for a simple election involving three political parties, the Orange party, the Purple party, and the Yellow     party. In addition to the constructor method, you should implement the following methods:

reset() - sets all vote totals to zero

voteOrange() - casts one vote for the Orange party

votePurple() - casts one vote for the Purple party

voteYellow() - casts one vote for the Yellow party

getVotes() - returns (but does not print) atuplecontaining three integers representing the total votes for the three parties, in this order: (Orange, Purple, Yellow)

Question 2 Implement a slice method for the UnorderedList class. It should take two                 parameters, start and stop, and return a copy of the list starting at the start position and going up

to but not including the stop position. (Note: You only need to submit your implementation of

the slice method if you use the UnorderedList class definition from thisColab notebook.)

Question 3 Implement a stack using linked lists.

Question 4 Implement a queue using linked lists.

Question 5 Implement a deque using linked lists.

Question 6 The UnorderedList class definition from thisColab notebookis called a singly linked

list because each node has a single reference to the next node in sequence. An alternative             implementation is known as a doubly linked list. In this implementation, each node has a             reference to the next node (commonly called next) as well as a reference to the preceding node    (commonly called back). The head reference also contains two references, one to the first node in the linked list and one to the last. Use a doubly linked list to implement the deque ADT one more time. Name the class Deque2(), and use the other method names given in Chapter 4.16 in your     digital textbook.