1 / 9

Lab 7

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.

hans
Download Presentation

Lab 7

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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

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

More Related