Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 Lab 7 Queue ADT

2 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).

3 OVERVIEW This is an example of a Queue:

4 Elements The elements in a queue are of generic type Object.

5 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).

6 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.

7 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.

8 Methods boolean isEmpty ( ) Precondition: None. Postcondition: Returns true if a queue is empty. Otherwise, returns false. boolean isFull ( ) 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.

9 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 Lqueue class It should be complete. Submit by email before your lab time


Download ppt "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."

Similar presentations


Ads by Google