Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 20, Problem 4FTE

Explanation of Solution

Program purpose:

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

Blurred answer
Students have asked these similar questions
Queue abcQ = new Queue (); Queue out = new Queue (); //statements to insert value 1, 2, 3, 4, 5 into abcQ for (int i = 0; i < 5; i++) { int a = Integer.parseInt (abcQ.dequeue ().tostring ()); int b = Integer.parseInt (abcQ.dequeue ().tostring ()); abcQ.enqueue (a); abcQ.enqueue (b); out.enqueue (a + b); for (int i = 0; i < 5; i++) System.out.print (abcQ.dequeue () + " "); System.out.println ("\n") ; for (int i = 0; i < 5; i++) System.out.print (out.dequeue () + " "); (- ks)
Find the output of the following program code if the following values have been inserted into abcQ: 1 2 4 5
In linked list implementation of a queue, the important condition for a queue to be empty is? a) FRONT is null  b) REAR is null  c) LINK is empty  d) FRONT == REAR-1
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education