Professional Documents
Culture Documents
Write a generic data type for a deque and a randomized queue. The goal of this assignment is to
implement elementary data structures using arrays and linked lists, and to introduce you to generics
and iterators.
Dequeue. A double-ended queue or deque (pronounced "deck") is a generalization of a stack and a
queue that supports inserting 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> {
public Deque()
// construct an empty deque
public boolean isEmpty()
// is the deque empty?
public int size()
// return the number of items on the deque
public void addFirst(Item item)
// insert the item at the front
public void addLast(Item item)
// insert the item at the end
public Item removeFirst()
// delete and return the item at the front
public Item removeLast()
// delete and return the item at the end
public Iterator<Item> iterator()
// return an iterator over items in order
from front to end
public static void main(String[] args)
// unit testing
}
Palindrome must complete in linear time in the size of the input. You may use a Deque
or a RandomizedQueue as well as a constant amount of extra memory.
% echo AAAACGTTTT | java Palindrome
true
% echo AAAACTTTT | java Palindrome
false
% echo AGCTAGCT | java Palindrome
true
% echo agctagct | java Palindrome
false
% echo GC | java Palindrome
true
% echo AGCTTCGA | java Palindrome
false
% echo | java Palindrome
true
% echo A | java Palindrome
false
Note: The sample input/output above assume that the program is being run from the command line.
If you are using NetBeans 7.3 or 8.0 then in order to pass arguments to java application try to do
following:
Run->Set Project Configuration->Customise->Arguments[write here your arguments here]->Ok
Then run your project:
Run->Run Project[F6]
The Output tab at the bottom also takes input if your program is waiting for input. Just type under
the last output line and hit enter.
Deliverables. Submit the data types RandomizedQueue.java and Deque.java. Each data
type should include its own main() that thoroughly tests the associated operations. You may not
call any library functions other than those in stdlib.jar and Integer.parseInt(). Also
submit the client programs Subset.java and Palindrome.java.