JS Priority queue ordering. When you are out of the team, first identify the highest priority elements, and then follow the FIFO first-out team.
/** Priority Queue * When out of the team, first identify the highest priority elements, and then follow the FIFO first-out team. * */functionQueue () { This. DataStore = [];//an array of storage queues, initialized to null This. enqueue = Enqueue;//add an element to the tail of the queue This. dequeue = dequeue;//when you are out of the team, first identify the highest priority elements, and then follow the FIFO first-out team. This. Thefront = Thefront;//read the elements of the first team This. back = back;//the element that takes the tail of the team This. tostrings = tostrings;//Show all elements in a queue This. empty = Empty;//determine if the queue is empty}/*define the object that stores the queue element first*/functionPatient (name,code) { This. name = name;//code is an integer that indicates the priority of the patient This. Code =Code;}functionEnqueue (Element) { This. Datastore.push (Element);}functiondequeue () {varMinindex = 0; varPriority = This. datastore[0].code; for(vari = 1;i< This. datastore.length;i++){ if( This. Datastore[i].code <Priority ) { Priority= This. Datastore[i].code; Minindex=i; } } return This. Datastore.splice (minindex,1);}functionThefront () {return This. datastore[0];}functionBack () {return This. datastore[ This. datastore.length-1];}functiontostrings () {return This. DataStore;}functionempty () {if( This. Datastore.length = = 0){ return true; }Else{ return false; }}/*implementation of the priority queue*/vared =NewQueue ();varp =NewPatient ("AA", 5); Ed.enqueue (p);varp =NewPatient ("BB", 4); Ed.enqueue (p);varp =NewPatient ("CC", 3); Ed.enqueue (p);varp =NewPatient ("DD", 3); Ed.enqueue (p);varp =NewPatient ("ee", 1); Ed.enqueue (P); Console.log (Ed.tostrings ()); Console.log (Ed.dequeue ()) ;//[Patient {name: ' ee ', code:1}]Console.log (Ed.dequeue ());//[Patient {name: ' CC ', code:3}]Console.log (Ed.dequeue ());//[Patient {name: ' DD ', code:3}]
JS Priority queue ordering. When you are out of the team, first identify the highest priority elements, and then follow the FIFO first-out team.