90 likes | 207 Vues
Lab 7. Queue ADT. OVERVIEW. The queue is one example of a constrained linear data structure. The elements in a queue are ordered from least recently added (the front) to most recently added (the rear). OVERVIEW. This is an example of a Queue:. Elements.
E N D
Lab 7 Queue ADT
OVERVIEW • The queue is one example of a constrained linear data structure. The elements in a queue are ordered from least recently added (the front) to most recently added (the rear).
OVERVIEW • This is an example of a Queue:
Elements • The elements in a queue are of generic type Object.
Structure • The queue elements are linearly ordered from least recently added (the front) to most recently added (the rear). Elements are inserted at the rear of the queue (enqueued) and are removed from the front of the queue (dequeued).
Constructors Queue ( ) Precondition: None. Postcondition: Default Constructor. Calls setup, which creates an empty queue and (if necessary) allocates enough memory for a queue containing DEF_MAX_QUEUE_SIZE (a constant value) elements. Queue ( int size ) Precondition: size > 0. Postcondition: Constructor. Calls setup, which creates an empty queue and (if necessary) allocates enough memory for a queue containing size elements. void setup ( int size ) Precondition: size > 0. A helper method for the constructors. Is declared private since only queue constructors should call this method. Postcondition: Creates an empty queue of a speciÞc size (where applicable) based on the value of size received from the constructor.
Methods void enqueue ( Object newElement ) Precondition: Queue is not full and newElement is not null. Postcondition: Inserts newElement at the rear of a queue. Object dequeue ( ) Precondition: Queue is not empty. Postcondition: Removes the least recently added (front) element from a queue and returns it. void clear ( ) Precondition: None. Postcondition: Removes all the elements in a queue.
Methods booleanisEmpty ( ) Precondition: None. Postcondition: Returns true if a queue is empty. Otherwise, returns false. booleanisFull ( ) Precondition: None. Postcondition: Returns true if a queue is full. Otherwise, returns false. void showStructure ( ) Precondition: None. Postcondition: Outputs the elements in a queue. If the queue is empty, outputs Empty queue. Note that this operation is intended for testing/debugging purposes only.
You should .. Implement the operations in the Lqueue ADT using a singly linked list to store the queue elements. Each node in the linked list should contain a queue element (element) and a reference to the node containing the next element in the queue (next). Your implementation also should maintain references to the nodes containing the front and rear elements in the queue (front and rear). In the LQueue constructors these front and rear references should be initialized to null. Base your implementation on the following incomplete class definitions from the file LQueue.java. • Send me Lqueueclass • It should be complete. • Submit by email before your lab time