Skip to content

Commit

Permalink
Implementation of Priority Queue using Heap
Browse files Browse the repository at this point in the history
  • Loading branch information
otienogeoffrey812 committed Oct 20, 2023
1 parent 49f17fa commit 0d0c5d8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The repository provides the following key operations:
- Insertion
- Removal
- Heap Sort
- Priority Queue

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/artman/Heap.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.artman;

public class Heap {
private int[] items = new int[100];
private int[] items = new int[10];
private int size;
public void insert(int value){
if (isFull()) throw new IllegalStateException();
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/com/artman/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class Main {
public static void main(String[] args) {
Heap heap = new Heap();
// Heap heap = new Heap();
// heap.insert(50);
// heap.insert(45);
// heap.insert(39);
Expand All @@ -15,8 +15,16 @@ public static void main(String[] args) {
// heap.remove();
// heap.remove();

int[] arrays = {5, 3, 10, 1, 4, 2};
heap.heapSort(arrays);
System.out.println(Arrays.toString(arrays));
// int[] arrays = {5, 3, 10, 1, 4, 2};
// heap.heapSort(arrays);
// System.out.println(Arrays.toString(arrays));
PriorityQueue queue = new PriorityQueue();
queue.enqueue(5);
queue.enqueue(3);
queue.enqueue(10);
queue.enqueue(1);
queue.enqueue(4);
queue.enqueue(2);
queue.dequeue();
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/artman/PriorityQueue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.artman;

public class PriorityQueue {
private Heap heap = new Heap();
public void enqueue(int item){
heap.insert(item);
}
public int dequeue(){
return heap.remove();
}
public boolean isEmpty(){
return heap.isEmpty();
}
}

0 comments on commit 0d0c5d8

Please sign in to comment.