In: Computer Science
You must write the correct code for all member methods so that queue functionality can be obtained. Changes to the class definition, instance variables, and signatures of the membership method are not allowed. This class has no main method.
package javaclass;
/**
* A queue structure of Movie objects. Only the Movie values contained
* in the queue are visible through the standard queue methods. The Movie
* values are stored in a DoubleLink object provided in class as attribute.
*
*
*
* @version 2013-07-04
*
* @param Movie
* this data structure value type.
*/
public class DoubleQueue {
// First node of the queue
private DoubleLink values = null;
/**
* Combines the contents of the left and right Queues into the current
* Queue. Moves nodes only - does not move value or call the high-level
* methods insert or remove. left and right Queues are empty when done.
* Nodes are moved alternately from left and right to this Queue.
*
* @param source1
* The front Queue to extract nodes from.
* @param source2
* The second Queue to extract nodes from.
*/
public void combine(final DoubleQueue source1,
final DoubleQueue source2) {
// your code here
}
/**
* Adds value to the rear of the queue.
*
* @param value
* The value to added to the rear of the queue.
*/
public void insert(final Movie value) {
// your code here
}
/**
* Returns the front value of the queue and removes that value from the
* queue. The next node in the queue becomes the new front node.
*
* @return The value at the front of the queue.
*/
public Movie remove() {
//your code here
return null;//you must change this statement as per your requirement
}
/**
* Returns the value at the front. Must be copy safe
*
* @return the value at the front.
*/
public Movie peekFront() {
// your code here
return null;//you must change this statement as per your requirement
}
/**
* Returns the value at the rear. Must be copy safe.
*
* @return the value at the rear.
*/
public Movie peekRear() {
// your code here
return null;//you must change this statement as per your requirement
}
/**
* Returns all the data in the queue in the form of an array.
*
* @return The array of Movie elements. Must be copy safe
*/
public final Movie [] toArray() {
//your code here
return null;//you must change this statement as per your requirement
}
}
Double link class
package javaclass;
/**
* The class for doubly-linked data structures. Provides attributes
* and implementations for getLength, isEmpty, and toArray methods.
* The head attribute is the first node in any doubly-linked list and
* last is the last node.
*
* @author
* @version 2017-11-01
*
*/
public class DoubleLink {
// First node of double linked list
private DoubleNode head = null;
// Number of elements currently stored in linked list
private int length = 0;
// Last node of double linked list.
private DoubleNode last = null;
/**
* Adds a new Movie element to the list at the head position
* before the previous head, if any. Increments the length of the List.
*
* @param value
* The value to be added at the head of the list.
*
* @return true if node is added successfully, else false.
*/
public final boolean addNode(final Movie value) {
//your code here
return false;//you must change this statement as per your requirement
}
/**
* Removes the value at the front of this List.
*
* @return The value at the front of this List.
*/
public Movie removeFront() {
// your code here
return null;//you must change this statement as per your requirement
}
/**
* Returns the head element in the linked structure. Must be copy safe.
*
* @return the head node.
*/
public final DoubleNode getHead() {
//your code here
return null;//you must change this statement as per your requirement
}
/**
* Returns the current number of elements in the linked structure.
*
* @return the value of length.
*/
public final int getLength() {
//your code here
return -1;//you must change this statement as per your requirement
}
/**
* Returns the last node in the linked structure. Must be copy safe.
*
* @return the last node.
*/
public final DoubleNode getLast() {
//your code here
return null;//you must change this statement as per your requirement
}
/**
* Determines whether the double linked list is empty or not.
*
* @return true if list is empty, false otherwise.
*/
public final boolean isEmpty() {
//your code here
return true;//you must change this statement as per your requirement
}
/**
* Returns all the data in the list in the form of an array.
*
* @return The array of Movie elements. Must be copy safe
*/
public final Movie [] toArray() {
//your code here
return null;//you must change this statement as per your requirement
}
}
#include<iostream> using namespace std; #define SIZE 10 class Queue { int a[SIZE]; int rear; //same as tail int front; //same as head public: Queue() { rear = front = -1; } //declaring enqueue, dequeue and display functions void enqueue(int x); int dequeue(); void display(); }; // function enqueue - to add data to queue void Queue :: enqueue(int x) { if(front == -1) { front++; } if( rear == SIZE-1) { cout << "Queue is full"; } else { a[++rear] = x; } } // function dequeue - to remove data from queue int Queue :: dequeue() { return a[++front]; // following approach [B], explained above } // function to display the queue elements void Queue :: display() { int i; for( i = front; i <= rear; i++) { cout << a[i] << endl; } } // the main function int main() { Queue q; q.enqueue(10); q.enqueue(100); q.enqueue(1000); q.enqueue(1001); q.enqueue(1002); q.dequeue(); q.enqueue(1003); q.dequeue(); q.dequeue(); q.enqueue(1004); q.display(); return 0; }