Skip to content

Commit

Permalink
PriorityQueue come true.
Browse files Browse the repository at this point in the history
  • Loading branch information
liusishan committed Feb 26, 2019
1 parent bd374c2 commit c7d8a4e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @Auther: lss
* @Date: 2019/2/26 12:52
* @Description:
*/
public class PriorityQueue<E extends Comparable<E>> implements Queue<E> {

private MaxHeap<E> maxHeap;

public PriorityQueue() {
maxHeap = new MaxHeap<>();
}

@Override
public void enqueue(E e) {
maxHeap.add(e);
}

@Override
public E dequeue() {
return maxHeap.extractMax();
}

@Override
public E getFront() {
return maxHeap.findMax();
}

@Override
public int getSize() {
return maxHeap.size();
}

@Override
public boolean isEmpty() {
return maxHeap.isEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @Auther: lss
* @Date: 2019/2/26 12:51
* @Description:
*/
public interface Queue<E> {
void enqueue(E e);

E dequeue();

E getFront();

int getSize();

boolean isEmpty();


}

0 comments on commit c7d8a4e

Please sign in to comment.