public class Queue{ private int size; private Node front, rear; public void offer(T data) { Node tempNode = new Node(

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

public class Queue{ private int size; private Node front, rear; public void offer(T data) { Node tempNode = new Node(

Post by answerhappygod »

Public Class Queue T Private Int Size Private Node Front Rear Public Void Offer T Data Node Tempnode New Node 1
Public Class Queue T Private Int Size Private Node Front Rear Public Void Offer T Data Node Tempnode New Node 1 (49.57 KiB) Viewed 46 times
Public Class Queue T Private Int Size Private Node Front Rear Public Void Offer T Data Node Tempnode New Node 2
Public Class Queue T Private Int Size Private Node Front Rear Public Void Offer T Data Node Tempnode New Node 2 (54.37 KiB) Viewed 46 times
Public Class Queue T Private Int Size Private Node Front Rear Public Void Offer T Data Node Tempnode New Node 3
Public Class Queue T Private Int Size Private Node Front Rear Public Void Offer T Data Node Tempnode New Node 3 (10.64 KiB) Viewed 46 times
public class Queue<T>{ private int size; private Node front, rear; public void offer(T data) { Node tempNode = new Node(data); if(!isEmpty()) { rear.setNextNode (temp Node); rear = tempNode; }else{ front = rear = tempNode; size++; } public T poll(){ if(!isEmpty()){ TX = (T) front.getData(); size--; System.out.println("Poll was: x + ", and is now deleted!"); front = front.getNextNode(); return x; }else{ System.out.println("The queue is now empty!"); return (T) (new Integer (-999)); } } public T peek() { if(!isEmpty()) { TX = (T) front.getData(); size--; System.out.println("Peek was: + ", and is now deleted!"); return x; }else{ System.out.println("The queue is now empty!"); return (T) (now Tntorer 1.000).

SELSE2 System.out.println("The queue is now empty!"); return (T) (new Integer (-999)); } } public boolean isEmpty() { return (size = 0); } public void display(){ Node tempNode = front; if(!isEmpty()) { while(tempNode.getNextNode() != null){ System.out.println(tempNode.getData()); tempNode = tempNode.getNextNode(); } } System.out.println(tempNode.getData()); System.out.println("The queue is empty!"); } }

Modify the queue dass that we implemented in-class on April 18, using Linked List to add another method to access (or search) an element at a certain index from the queue. Hint: it would be a modified version of the display() method. You would be sending the index as an argument and you keep a counter. Instead of printing all elements, you print the element only when your counter matches the index,
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply