Concept explainers
Explanation of Solution
The given program is used to implement queue using linked list.
Syntax error:
An error that occurs on the source code of a program is referred as a “syntax error”, because the computer programs strictly follow the syntax rules. If the code fails to prove its language syntax format, then the compiler will throw an error.
Error in the code:
The operator “++” cannot be applied to a reference. Use front = front.next;
Correct statement:
/*removing the element from front by moving front to the next node.*/
front= front.next;
Corrected code:
//A linked implementation of a queue
int dequeue()
{
//checks whether the queue is empty
if(empty())
/*throws exception EmptyQueueException indicating the queue is empty*/
throw new EmptyQueueException();
/*if the queue is not empty then,
front element is reserved to a variable*/
int value= front...
Want to see the full answer?
Check out a sample textbook solutionChapter 20 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
- Implement a function void reverseQueue(QueueSLL&) that reverses the elements of a parameter queue. The function uses a stack for the reverse.arrow_forwardImplement a method concatenate in class LinkedQueue. This method should take all the elements of a queue sourceQ and append them to the end of another queue targetQ. The operation should result in sourceQ being an empty queue. Test this method in the main method of LinkedQueue. package queues;public class LinkedQueue<E> implements Queue<E> { private SinglyLinkedList<E> list = new SinglyLinkedList<>(); // an empty list public LinkedQueue() { } // new queue relies on the initially empty list @Override public int size() { return list.size(); } @Override public boolean isEmpty() { return list.isEmpty(); } @Override public void enqueue(E element) { list.addLast(element); } @Override public E first() { return list.first(); } @Override public E dequeue() { return list.removeFirst(); } public String toString() { return list.toString(); }}arrow_forwardJava(eclipse) Implement a method concatenate in class LinkedQueue. This method should take all the elements of a queue sourceQ and append them to the end of another queue targetQ. The operation should result in sourceQ being an empty queue. Test this method in the main method of LinkedQueue.arrow_forward
- The QueueInterface interface is a contract between the implementer of a Queue ADT and the programmer who uses it.Is it correct or incorrect?arrow_forwardThe QueueInterface interface represents an agreement between the implementer of a Queue ADT and the programmer who uses it.Is it correct or incorrect?arrow_forwardIn an ideal implementations of a queue, all operations are ______________________ .arrow_forward
- An ordinary queue implemented using an array of size CAPACITY gets full when: a. Front = (rear + 1) mod CAPACITY b. Rear = front c. Front = rear + 1 d. Rear = CAPACITY –arrow_forwardThe interface provided by a Queue ADT is a binding agreement between the implementer and the programmer. what do you think, true or falsearrow_forwardPush, pop, and enqueue operations are supported by a data type known as a stack-ended queue (steque). Give this ADT an API description. Create an implementation based on linked lists.arrow_forward
- The QueueInterface interface is an agreement between the implementer of a Queue ADT and the developer using that ADT. Thus, the question is: true or false?arrow_forwardA stack-ended queue, sometimes known as a steque, is a data type that allows push, pop, and enqueue operations. Make an API for this ADT. Create a linked-list implementation.arrow_forwardTrue or False? When implementing a queue with a linked list, the front of the queue is also the front of the linked list.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education