QuestionQuestion

In this programming assignment you are required to implement a queue data structure using a singly linked list. Write a Java program to implement the queue using a simple linked list instead of a fixed size array. You can assume the items to be stored in the queue are positive integers. You do not need to incorporate any ordering. However, the queue must have a front and a rear. Any item inserted to the queue will be inserted at rear and items must be deleted from front.

Programming:
Your main() method should be interactive (menu driven) and should give the following options to a
user:
i) Insert an item to the queue (at rear)
ii) Delete an item from the queue (from front)
iii) Display the item at front
iv) Display the item at rear
v) Display total number of items currently present in the queue
vi) Print the items currently present in the queue
vii) Quit
The program should start with the menu and the user should be able to choose any option from the menu. The menu should keep coming back, after completing each user choice, until the user selects ‘Quit’ option. Also, include proper error checking (for example, when someone tries to delete item from an empty queue, or tries to display items of an empty queue) with appropriate message(s).

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.util.Scanner;

public class LinkedlistQue {

    /**
    * private class holds data and connection to other item in the list
    */
    private class Node{      
       int item; // data
       Node next; // connector
       /**
         * constructor
         * @param item
         * @param next
         */
       public Node(int item, Node next) {
            this.item = item;
            this.next = next;
       }      
    };
      
    private Node front; // front reference   
    private Node rear; // rear reference
    private int total;// number of item in queue...

By purchasing this solution you'll be able to access the following files:
Solution.java.

$25.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats