Rules:  Corner cases.  Throw the specified exception for the following corner cases: Throw an IllegalArgumentException if the client calls either addFirst() or addLast() with a null argument. Throw a java.util.NoSuchElementException if the client calls either removeFirst() or removeLast when the deque is empty. Throw a java.util.NoSuchElementException if the client calls the next() method in the iterator when there are no more items to return. Unit testing.  Your main() method must call directly every public constructor and method to help verify that they work as prescribed (e.g., by printing results to standard output). Performance requirements.  Your implementation must achieve the following worst-case performance requirements: A deque containing n items must use at most 48n + 192 bytes of memory, not including the memory for the items themselves. Each deque operation (including construction) must take constant time. Each iterator operation (including construction) must take constant time.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Rules: 

Corner cases.  Throw the specified exception for the following corner cases:

  • Throw an IllegalArgumentException if the client calls either addFirst() or addLast() with a null argument.
  • Throw a java.util.NoSuchElementException if the client calls either removeFirst() or removeLast when the deque is empty.
  • Throw a java.util.NoSuchElementException if the client calls the next() method in the iterator when there are no more items to return.

Unit testing.  Your main() method must call directly every public constructor and method to help verify that they work as prescribed (e.g., by printing results to standard output).

Performance requirements.  Your implementation must achieve the following worst-case performance requirements:

  • A deque containing n items must use at most 48n + 192 bytes of memory, not including the memory for the items themselves.
  • Each deque operation (including construction) must take constant time.
  • Each iterator operation (including construction) must take constant time.
Dequeue. A double-ended queue or deque (pronounced "deck") is a generalization of a stack and a queue that supports adding and removing items from either the front or the back of the data
structure. Create a generic data type Deque that implements the following API:
public class Deque<Item> implements Iterable<Item> {
// construct an empty deque
public Deque ()
// is the deque empty?
public boolean isEmpty()
// return the number of items on the deque
public int size()
// add the item to the front
public void addFirst (Item item)
// add the item to the back
public void addLast(Item item)
// remove and return the item from the front
public Item removeFirst()
// remove and return the item from the back
public Item removeLast()
// return an iterator over items in order from front to back
public Iterator<Item> iterator ()
// unit testing (required)
public static void main(String[] args)
}
Transcribed Image Text:Dequeue. A double-ended queue or deque (pronounced "deck") is a generalization of a stack and a queue that supports adding and removing items from either the front or the back of the data structure. Create a generic data type Deque that implements the following API: public class Deque<Item> implements Iterable<Item> { // construct an empty deque public Deque () // is the deque empty? public boolean isEmpty() // return the number of items on the deque public int size() // add the item to the front public void addFirst (Item item) // add the item to the back public void addLast(Item item) // remove and return the item from the front public Item removeFirst() // remove and return the item from the back public Item removeLast() // return an iterator over items in order from front to back public Iterator<Item> iterator () // unit testing (required) public static void main(String[] args) }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education