Question: My program is skipping some of the ticket objects when outputing the LinkedList how do I change it so that all the tickets are being
My program is skipping some ofthe ticketobjects when outputing the LinkedList how do I change it so that all the tickets are being outputted?Should sort the LinkedList so that higher priority Ticket objects come before lowerpriority Ticket objects.
public class Ticket int ticketID; String customerName; String issueDescription; int priority; Ticket next; Ticket previous;
public Ticketint ticketID, String customerName, String issueDescription, int priority this.ticketID ticketID; this.customerName customerName; this.issueDescription issueDescription; this.priority priority;
class TicketQueue Ticket head; Ticket tail; int size;
public TicketQueue head null; tail null; size ;
public Ticket enqueueTicket t if head null this.head t; this.tail t; tnext null; tprevious null; else tprevious tail; this.tail.next t; this.tail t; size; sortList; Call sortList after enqueuing return t;
public void sortList if size return; boolean swapped; do swapped false; Ticket current head; while currentnext null if currentpriority current.next.priority Ticket temp current; current current.next; current.previous temp.previous; temp.next current.next; current.next temp; if tempprevious null temp.previous.next current; else head current; if currentnext null current.next.previous temp; else tail temp; swapped true; else current current.next; while swapped;
public boolean isEmpty return size ;
public void printList Ticket current head; if head null System.out.printlnList is empty"; return; while current null System.out.printlncurrentticketID current.customerName current.issueDescription current.priority; current current.next;
public class Test public static void mainString args Ticket t new Ticket "John", "Internet connection issue", ; Ticket t new Ticket "Alex", "Request for account update", ; Ticket t new Ticket "John", "Request for account recovery", ; Ticket t new Ticket "John", "Unable access the system", ; Ticket t new Ticket "Sam", "Internet connection issue", ; TicketQueue list new TicketQueue; list.enqueuet; list.enqueuet; list.enqueuet; list.enqueuet; list.enqueuet; list.printList;
My output should be
John Internet connection issue John Unable access the system John Request for account recovery Alex Request for account update Sam Internet connection issue
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
