Created
November 19, 2015 00:06
-
-
Save rrmdn/8610fcf6e6399458b836 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.company; | |
| /** | |
| * Created by donnystark on 11/19/15. | |
| */ | |
| public class QueuePriority { | |
| DLL Front, Rear; | |
| int size = 0; | |
| private DLL temp; | |
| QueuePriority(DLL newDLL){ | |
| this.enqueue(newDLL); | |
| } | |
| void enqueue(DLL newDLL){ | |
| System.out.println("Enqueue " + newDLL.toString()); | |
| this.size++; | |
| if(this.Rear == null){ | |
| this.Rear = newDLL; | |
| this.Rear.prev = newDLL; | |
| this.Front = newDLL; | |
| this.Front.next = newDLL; | |
| } else { | |
| newDLL.prev = this.Rear; | |
| this.Rear.next = newDLL; | |
| this.Rear = this.Rear.next; | |
| } | |
| } | |
| DLL dequeue(){ | |
| if (size > 0){ | |
| size--; | |
| DLL temp = this.Front; | |
| DLL search = this.Front; | |
| boolean loop = true; | |
| do { | |
| if(search.priority < temp.priority){ | |
| search = temp; | |
| if(temp.next != null){ | |
| temp.prev.next = temp.next; | |
| temp.next.prev = temp.prev; | |
| } else { | |
| temp.prev.next = null; | |
| } | |
| } | |
| if(temp.next == null){ | |
| loop = false; | |
| } else { | |
| temp = temp.next; | |
| } | |
| }while (loop); | |
| // this.Front = this.Front.pointer; | |
| System.out.println("Dequeue " + search.toString()); | |
| return search; | |
| } | |
| else { | |
| System.out.println("There is no one here"); | |
| return null; | |
| } | |
| } | |
| } | |
| class DLL { | |
| DLL next, prev; | |
| String name; | |
| int priority; | |
| DLL(String name, int priority){ | |
| this.name = name; | |
| this.priority = priority; | |
| } | |
| @Override | |
| public String toString() { | |
| return "Name: "+this.name+" Priority: "+ this.priority; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment