Delete all occurrences of an element X15744


Statement
 

pdf   zip   tar

thehtml

In the public_files section of the problem statement, a class called PositionalList, which implements the Positional List ADT using a doubly-linked list, is defined. Extend the implementation of this class with a new public method delete_all(self, e). This method deletes all occurrences of element e in the list instance calling it.

For example, if t is an instance of the class PositionalList that represents the following list

1, 2, 3, 1, 1, 4, 1, 5, 6, 1

after executing the statement t.delete_all(1), the object t will represent the list

2, 3, 4, 5, 6

In particular, you should add the following public method to the PositionalList class:

  def delete_all(self, e):
    """ Deletes all occurrences of e in self. """
Public test cases
  • Input

    10
    1 2 3 1 1 4 1 5 6 1
    1

    Output

    list t:
    1, 2, 3, 1, 1, 4, 1, 5, 6, 1
    1, 6, 5, 1, 4, 1, 1, 3, 2, 1
    list after deletion t:
    2, 3, 4, 5, 6
    6, 5, 4, 3, 2
    
  • Information
    Author
    Language
    English
    Official solutions
    Python
    User solutions
    Python