deque_array.py - -dequeue_array.py Array version of the Dequeue ADT-Author David Brown ID 999999999 Email [email protected]_updated = from copy import

deque_array.py - -dequeue_array.py Array version of the...

This preview shows page 1 - 3 out of 3 pages.

""" ------------------------------------------------------- dequeue_array.py Array version of the Dequeue ADT. ------------------------------------------------------- Author: David Brown ID: 999999999 Email: [email protected] __updated__ = "2017-02-24" ------------------------------------------------------- """ from copy import deepcopy class Deque: def __init__(self): """ ------------------------------------------------------- Initializes an empty deque. Use: d = deque() ------------------------------------------------------- Postconditions: Initializes an empty deque. ------------------------------------------------------- """ self._values = [] return def is_empty(self): """ ------------------------------------------------------- Determines if the deque is empty. Use: b = d.is_empty() ------------------------------------------------------- Postconditions: returns True if the deque is empty, False otherwise. ------------------------------------------------------- """ return len(self._values) == 0 def __len__(self): """ ------------------------------------------------------- Returns the size of the deque. Use: n = len(d) ------------------------------------------------------- Postconditions: returns the number of values in the deque. ------------------------------------------------------- """ return len(self._values) def insert_front(self, value): """ ------------------------------------------------------- Inserts a copy of value into the front of the deque. Use: d.insert_front(value) ------------------------------------------------------- Preconditions: value - a data element (?) Postconditions:
Image of page 1

Subscribe to view the full document.

a copy of value is added to the front of the deque. ------------------------------------------------------- """ self._values.insert(0, deepcopy(value)) return def insert_rear(self, value): """ ------------------------------------------------------- Inserts a copy of value into the rear of the deque. Use: d.insert_rear(value) ------------------------------------------------------- Preconditions: value - a data element (?) Postconditions: a copy of value is added to the rear of the deque.
Image of page 2
Image of page 3
  • Fall '13
  • sta
  • deque

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes