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 Ticket(int 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 =0; }
public Ticket enqueue(Ticket t){ if (head == null){ this.head = t; this.tail = t; t.next = null; t.previous = null; } else { t.previous = tail; this.tail.next = t; this.tail = t; } size++; sortList(); // Call sortList after enqueuing return t; }
public void sortList(){ if (size <=1) return; boolean swapped; do { swapped = false; Ticket current = head; while (current.next != null){ if (current.priority > current.next.priority){ Ticket temp = current; current = current.next; current.previous = temp.previous; temp.next = current.next; current.next = temp; if (temp.previous != null) temp.previous.next = current; else head = current; if (current.next != null) current.next.previous = temp; else tail = temp; swapped = true; } else { current = current.next; }}} while (swapped); }
public boolean isEmpty(){ return size ==0; }
public void printList(){ Ticket current = head; if (head == null){ System.out.println("List is empty"); return; } while (current != null){ System.out.println(current.ticketID +""+ current.customerName +""+ current.issueDescription +""+ current.priority); current = current.next; }}}
public class Test { public static void main(String[] args){ Ticket t1= new Ticket(101, "John", "Internet connection issue", 1); Ticket t2= new Ticket(102, "Alex", "Request for account update", 3); Ticket t3= new Ticket(103, "John", "Request for account recovery", 2); Ticket t4= new Ticket(104, "John", "Unable access the system", 1); Ticket t5= new Ticket(105, "Sam", "Internet connection issue", 3); TicketQueue list = new TicketQueue(); list.enqueue(t1); list.enqueue(t2); list.enqueue(t3); list.enqueue(t4); list.enqueue(t5); list.printList(); }}
My output should be
101 John Internet connection issue 1104 John Unable access the system 1103 John Request for account recovery 2102 Alex Request for account update 3105 Sam Internet connection issue 3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!